UIlabel layer.cornerRadius not working in iOS 7.1

后端 未结 8 1916
时光说笑
时光说笑 2021-01-30 04:40

I\'m currently looking at a UILabel with the property addMessageLabel.layer.cornerRadius = 5.0f; On a device with iOS 7.0 installed, it has rounded corners. On a de

8条回答
  •  旧巷少年郎
    2021-01-30 05:19

    My issue was a bit different.

    While I did do btn.clipsToBounds = true

    I wasn't setting doing:

    btn.layer.cornerRadius = 20
    

    Because I had different screen sizes. Instead I followed this answer and did:

    override func layoutSubviews() {
        seeMoreButton.layer.cornerRadius = seeMoreButton.bounds.size.height / 2
    }
    

    It wasn't working because I forgot to add super.layoutSubviews(). The correct code is:

    override func layoutSubviews() {
        super.layoutSubviews()
        seeMoreButton.layer.cornerRadius = seeMoreButton.bounds.size.height / 2
    }
    

提交回复
热议问题