Set the property clipsToBounds
to true
addMessageLabel.clipsToBounds = true
I think the best way to set corner radius is:
and be sure the "Clip Subviews" is checked:
Checking "Clip Subviews" is equal to the code addMessageLabel.clipsToBounds = YES;
.
Try the followings,
[[addMessageLabel layer] setCornerRadius:5.0f];
[[addMessageLabel layer] setMasksToBounds:YES];
//or
[addMessageLabel setClipsToBounds:YES];
Swift
addMessageLable.layer.cornerRadius = 5.0
addMessageLable.layer.masksToBounds = true
//or
addMessageLable.layer.clipsToBounds = true
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
}
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With