UIlabel layer.cornerRadius not working in iOS 7.1

2019-03-08 00:13发布

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 device with iOS 7.1 installed, it does not have rounded corners.

Is this just a bug with iOS 7.1?

7条回答
劫难
2楼-- · 2019-03-08 00:14

I have tried the below one and i got an successful output.

yourlabelname.layer.cornerRadius = 10.0f;
[yourlabelname setClipsToBounds:YES];

Is there something else which is stopping you?

查看更多
地球回转人心会变
3楼-- · 2019-03-08 00:15

Add the below two line and check it.

[[addMessageLabel layer] setCornerRadius:5.0f];
[[addMessageLabel layer] setMasksToBounds:YES];

OR

[addMessageLabel setClipsToBounds:YES];
查看更多
▲ chillily
4楼-- · 2019-03-08 00:21
 //works perfect in Swift 2.0 for a circular or round image          


@IBOutlet var theImage: UIImageView!
        override func viewDidLoad() {
            super.viewDidLoad()
    //Make sure the width and height are same
            self.theImage.layer.cornerRadius = self.theImage.frame.size.width / 2
            self.theImage.layer.borderWidth = 2.0
            self.theImage.layer.borderColor = UIColor.whiteColor().CGColor
            self.theImage.clipsToBounds = true

        }
查看更多
叛逆
5楼-- · 2019-03-08 00:23

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
}
查看更多
乱世女痞
6楼-- · 2019-03-08 00:27
yourlabelname.layer.cornerRadius = yourlabelname.frame.size.width/2;
[yourlabelname setClipsToBounds:YES];

Make sure you are checking with appropriate Deployment target.

查看更多
Animai°情兽
7楼-- · 2019-03-08 00:35

Set the property clipsToBounds to true

addMessageLabel.clipsToBounds = true
查看更多
登录 后发表回答