IPhone : Why I got this strange behavior for UIView with gradient background?

on Tuesday, February 24, 2015

I am trying to add gradient layer to a UIView that contains a UILabel.


My UIView implementation:



class ContentView: UIView {
override init() {
super.init()
styleIt()
}

override init(frame: CGRect) {
super.init(frame: frame)
styleIt()
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
styleIt()
}

private func styleIt() {
var gradient = CAGradientLayer()
gradient.colors = [Utils.Colors.gray_ee.CGColor, Utils.Colors.gray_dd.CGColor]
gradient.frame = bounds

layer.insertSublayer(gradient, atIndex: 0)

layer.borderColor = Utils.Colors.gray_aa.CGColor
layer.borderWidth = 1

layer.cornerRadius = 7.0
}
}


But here is what I got as a result shown in the iPhone 6 iOS Simulator


Only the UIView with cornerRadius is having a strange behavior all other elements in this screenshot are not UIView elements.


I have tried to comment border-related code and radius code, but still same issue.


enter image description here


0 comments:

Post a Comment