需要帮助贴合标签,以便左侧和右侧填充。 代码位于底部。
@IBOutlet weak var header: UILabel!
override func viewDidLoad() {
header.adjustsFontSizeToFitWidth = true
let rectShape = CAShapeLayer()
rectShape.bounds = self.header.frame
rectShape.position = self.header.center
rectShape.path = UIBezierPath(roundedRect: self.header.bounds, byRoundingCorners: [.bottomLeft , .bottomRight], cornerRadii: CGSize(width:300, height: 200)).cgPath
self.header.layer.backgroundColor = UIColor.green.cgColor
//Here I'm masking the textView's layer with rectShape layer
self.header.layer.mask = rectShape
super.viewDidLoad()
答案 0 :(得分:0)
您可以将代码块放入viewDidAppear(_:)
来解决此问题。在此方法中,将更正大小。
@IBOutlet weak var header: UILabel!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
header.adjustsFontSizeToFitWidth = true
let rectShape = CAShapeLayer()
rectShape.bounds = self.header.frame
rectShape.position = self.header.center
rectShape.path = UIBezierPath(roundedRect: self.header.bounds, byRoundingCorners: [.bottomLeft , .bottomRight], cornerRadii: CGSize(width:300, height: 200)).cgPath
self.header.layer.backgroundColor = UIColor.green.cgColor
//Here I'm masking the textView's layer with rectShape layer
self.header.layer.mask = rectShape
}