Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Diego Aguirre
Diego Aguirre
13,211 Points

Using a UILabel to make a custom circular Badge.

I have a the following extension that I use to create a custom circular badge. For now it works great for number 2 and up but whenever the number 1 is passed to it the badge loses it's nice circular shape.

Any ideas on how to fix this?

extension UILabel {
    func addBadge(label: UILabel, badgeCount: String) {
        label.clipsToBounds = true
        label.layer.cornerRadius = label.font.pointSize * 0.60
        label.backgroundColor = UIColor.red
        label.textColor = UIColor.white
        label.text = " \(badgeCount) "; // note spaces before and after text
    }
}

image of issue