UIView background color in Swift

后端 未结 8 1013
Happy的楠姐
Happy的楠姐 2020-12-25 09:51

Is there a way to set the UIView background color with Swift?

I know that in Objective-C, you would use self.view.backgroundColor = [UIColor redColor];,

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 10:25

    You can use this extension as an alternative if you're dealing with RGB value.

    extension UIColor {
        static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
            return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
          }
        }
    

提交回复
热议问题