美文网首页
关于UIbutton使用var还是let

关于UIbutton使用var还是let

作者: wtz | 来源:发表于2016-08-08 16:19 被阅读0次

var button = UIButton()
button.frame = CGRectMake(100, 200, 100, 100)
button.backgroundColor = UIColor.redColor()
self.view.addSubview(button)

在swift中,如果这么写会提示Variable 'button' was never mutated,编译器会让我把var换成let。

之后
let button = UIButton()
button.frame = CGRectMake(100, 200, 100, 100)
button.backgroundColor = UIColor.redColor()
self.view.addSubview(button)
成功运行

相关文章

网友评论

      本文标题:关于UIbutton使用var还是let

      本文链接:https://www.haomeiwen.com/subject/agjrsttx.html