Set background color for only part of UIView

前端 未结 6 2648
生来不讨喜
生来不讨喜 2021-02-20 09:33

I want the bottom (not quite half) of my UIView to be a different color than the top.

I\'m wondering if I should create a CGRect and then color that? Is this along the r

6条回答
  •  伪装坚强ぢ
    2021-02-20 10:08

    You can also add an CALayer as a sub layer to your view. Include CoreGraphics and QuartzCore frameworks and create a CGRect with the desired form factor in your drawRect method. Instantiate a CALayer with the rect and add it to the view's layer using [self.layer addSublayer:theLayer]. Before adding it use the CALayer's -setBackgroundColor: method.

    If this is inside of a View Controller instead of a View subclass, do exactly the same in the viewDidLoad method.

    Bryan

提交回复
热议问题