UIlabel layer.cornerRadius not working in iOS 7.1

IosUiviewIos7UilabelCornerradius

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

Set the property clipsToBounds to true

addMessageLabel.clipsToBounds = true

Solution 2 - Ios

I think the best way to set corner radius is:

enter image description here

and be sure the "Clip Subviews" is checked:

enter image description here

Checking "Clip Subviews" is equal to the code addMessageLabel.clipsToBounds = YES;.

Solution 3 - Ios

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

Solution 4 - Ios

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
}

Solution 5 - Ios

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?

Solution 6 - Ios

 //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
        
        }

Solution 7 - Ios

yourlabelname.layer.cornerRadius = yourlabelname.frame.size.width/2;
[yourlabelname setClipsToBounds:YES];

Make sure you are checking with appropriate Deployment target.

Solution 8 - Ios

Add the Following Code as extension for UIView

//// Story board Extra Feature for create border radius, border width and border Color
extension UIView {
    /// corner radius
    @IBInspectable var borderColor: UIColor? {
        set {
            layer.borderColor = newValue!.cgColor
        }
        get {
            if let color = layer.borderColor {
                return UIColor(cgColor: color)
            } else {
                return nil
            }
        }
    }
    @IBInspectable var borderWidth: CGFloat {
        set {
            layer.borderWidth = newValue
        }
        get {
            return layer.borderWidth
        }
    }
    @IBInspectable var cornerRadius: CGFloat {
        set {
            layer.cornerRadius = newValue
            clipsToBounds = newValue > 0
        }
        get {
            return layer.cornerRadius
        }
    }
}

After that you will get the following attributes in interface builder itself.!

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMike VView Question on Stackoverflow
Solution 1 - IosRaheel SadiqView Answer on Stackoverflow
Solution 2 - IosAllenView Answer on Stackoverflow
Solution 3 - IosTapas PalView Answer on Stackoverflow
Solution 4 - IosmfaaniView Answer on Stackoverflow
Solution 5 - IosMano RajendranView Answer on Stackoverflow
Solution 6 - IosNaishtaView Answer on Stackoverflow
Solution 7 - IosiAmita SinghView Answer on Stackoverflow
Solution 8 - IosBharathRaoView Answer on Stackoverflow