Ho costruito una vista che appare dal basso e si nasconde dopo un po 'e funziona bene, ma voglio farlo nella modalita' UIView
come modale, ho guardato su internet ma non potevo ottenere o capire come farlo.Classe UIView personalizzata - Swift
snake = UIView(frame: CGRect(x: 0 , y: self.view.frame.size.height-66, width: self.view.frame.size.width, height: 66))
snake.backgroundColor = UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 1.0)
let label = UILabel(frame: CGRect(x: 12, y: 8, width: snake.frame.size.width-90, height: 50))
label.text = "Connection error please try again later!!"
label.textColor = UIColor.whiteColor()
label.numberOfLines = 0
label.font = UIFont.systemFontOfSize(14)
snake.addSubview(label)
let button = UIButton(frame: CGRect(x: snake.frame.size.width-87, y: 8, width: 86, height: 50))
button.setTitle("OK", forState: UIControlState.Normal)
button.setTitleColor(UIColor(red: 76/255, green: 175/255, blue: 80/255, alpha: 1.0), forState: UIControlState.Normal)
button.addTarget(self, action: "hideSnackBar:", forControlEvents: UIControlEvents.TouchUpInside)
snake.addSubview(button)
self.view.addSubview(snake)
come iniziare con questa classe ho idea, io sto creando la vista a livello di codice con la sua cornice e ho bisogno di impostare le proprietà per il pulsante per esempio, o l'etichetta e creare la vista da ogni classe.
class snake: UIView {
override init (frame : CGRect) {
super.init(frame : frame)
}
convenience init() {
self.init(frame:CGRect.zero)
}
required init(coder aDecoder: NSCoder) {
fatalError("This class does not support NSCoding")
}
}
Bene grande, ma ancora una domanda se ho bisogno di impostare una proprietà per l'etichetta quando ho bisogno di utilizzare la vista, come è è possibile? ho bisogno di un setter ma puoi mostrarmi un esempio? –
Ho aggiornato il mio post –
@Nguyen Hoan invece di una classe, come spingere questo codice in una struttura? –