swift - Swift 中的 UIView 背景颜色

标签 swift ios8 xcode6

有没有办法用 Swift 设置 UIView 背景颜色?

我知道在 Objective-C 中,您会使用 self.view.backgroundColor = [UIColor redColor];,但这在 Swift 中的工作方式不同。我环顾四周,因为 Swift 才大约一周大,我找不到答案。

有人有什么建议吗?

最佳答案

self.view.backgroundColor = UIColor.redColor()

在 Swift 3 中:

self.view.backgroundColor = UIColor.red

关于swift - Swift 中的 UIView 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24112272/

相关文章:

ios - 带有用户文本+静态标记的 UITextField

swift - 从单个串行队列访问 Swift 实例变量导致 Thread Sanitizer 问题

ios - 如何使 MGLPolyline 可点击?

ios - iOS8 本地通知可以触发代码吗?

ios - 为什么在字符串数组上使用连接会导致段错误 : 11 error on archiving in XCode?

swift - 快速解析 XML 数据

ios - UIImageView 无法在自调整单元格 iOS 8 中正确调整大小

ios - 约束更改时的自动布局 UIView 不会为 iOS 7 设置动画

ios - 如何在 iOS8 中使用 iOS touch ID 映射第三方应用凭证?

ios - swift 错误 : prefix/postfix '=' is reserved