UIView background color in Swift

后端 未结 8 1017
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:31

    If you want to set your custom RGB color try this:

    self.view.backgroundColor = UIColor(red: 20/255.0, green: 106/255.0, blue: 93/255.0, alpha: 1)

    Don't forget to keep /255.0 for every color

提交回复
热议问题