8
我已经建立了一个视图,从底部出现,并在一段时间后隐藏,它运作良好,但我想使它在UIView
类作为模式,我看着互联网,但我不能'不知道该怎么做。自定义UIView类 - 斯威夫特
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)
如何启动这一类,我不知道,我与它的框架创建视图编程,我需要为例子或标签按钮设置属性和创建任何类的观点。
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")
}
}
那么大,但多了一个问题,如果我需要设置一个属性标签时,我需要使用的观点,怎么有可能吗?我需要一个二传手,但你可以给我看一个例子吗? –
我更新了我的帖子 –
@Nguyen Hoan而不是类,如何将此代码推入结构? –