- The badge is a subclass of UILabel view.
- It can be created and customized from the Storyboard or programatically.
- Supports iOS 7+.
Copy SwiftBadge.swift to your project.
- Drag a Label to your view.
- Set its
class
toSwiftBadge
in identity inspector.
- Set the badge properties in the attributes inspector.
let badge = SwiftBadge()
view.addSubview(badge)
// Position the badge ...
See example of how to create and position the badge from code in the demo app.
// Text
badge.text = "2"
// Insets
badge.insets = CGSize(width: 12, height: 12)
// Font
badge.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
// Text color
badge.textColor = UIColor.yellowColor()
// Badge color
badge.badgeColor = UIColor.blackColor()
// Shadow
badge.shadowOpacityBadge = 0.5
badge.shadowOffsetBadge = CGSize(width: 0, height: 0)
badge.shadowRadiusBadge = 1.0
badge.shadowColorBadge = UIColor.blackColor()
// No shadow
badge.shadowOpacityBadge = 0
// Border width and color
badge.borderWidth = 5.0
badge.borderColor = UIColor.magentaColor()
This project includes a demo app.
Here are some alternative badges for iOS.
- ckteebe/CustomBadge
- JaviSoto/JSBadgeView
- mikeMTOL/UIBarButtonItem-Badge
- mustafaibrahim989/MIBadgeButton-Swift
- soffes/SAMBadgeView
- tmdvs/TDBadgedCell
- Thanks to amg1976 for adding a border and redesigning the drawing.
SwiftBadge is released under the MIT License.
If you found a bug or want to improve the badge feel free to create an issue.