MIBadgeButton-Swift icon indicating copy to clipboard operation
MIBadgeButton-Swift copied to clipboard

Badge displaying behind button content

Open ryryan opened this issue 8 years ago • 1 comments

Using the below code to display a UIBarButtonItem with a Font Awesome icon. The Badge displays behind the shopping cart.

Any help would be appreciated.

let button = MIBadgeButton(type: .Custom)
button.badgeString = String(qty)
button.frame = CGRectMake(0, 0, 55, 40)
button.badgeEdgeInsets = UIEdgeInsetsMake(15, 0, 0, 10)
button.titleLabel?.font = UIFont.fontAwesomeOfSize(30)
button.setTitle(String.fontAwesomeIconWithName(FontAwesome.ShoppingCart), forState: .Normal)
button.setTitleColor(UIColor.whiteColor(), forState: .Normal)
button.badgeBackgroundColor = UIColor(red: 147/255, green: 149/255, blue: 151/255, alpha: 1.0)
button.setTitleColor(UIColor(red: 147/255, green: 149/255, blue: 151/255, alpha: 0.6), forState: .Highlighted)
button.addTarget(self, action: #selector(DryCleaning.backToServices), forControlEvents: UIControlEvents.TouchUpInside)
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.rightBarButtonItem = barButton

ryryan avatar Jul 08 '16 15:07 ryryan

What is UIFont.fontAwesomeOfSize(30)? I don't get fontAwesome..

Below I change your code and it can display badge without behind anything.

let button = MIBadgeButton(type:.custom) button.badgeString = String("12") button.frame = CGRect(x: 0, y: 0, width: 50, height: 60) button.badgeEdgeInsets = UIEdgeInsetsMake(15, 0, 0, 10) //button.titleLabel?.font = UIFont.fontAwesomeOfSize(30) button.setTitle("asdf", for: .normal) button.setTitleColor(UIColor.red, for: .normal) button.badgeBackgroundColor = UIColor(red: 147/255, green: 149/255, blue: 151/255, alpha: 1.0) button.setTitleColor(UIColor(red: 147/255, green: 149/255, blue: 151/255, alpha: 0.6), for: .highlighted) //button.addTarget(self, action: #selector(DryCleaning.backToServices), forControlEvents: UIControlEvents.TouchUpInside) let barButton = UIBarButtonItem(customView: button) self.navigationItem.rightBarButtonItem = barButton self.title = "nav controller"

tomneo2004 avatar Oct 12 '16 08:10 tomneo2004