Skip to content

Instantly share code, notes, and snippets.

@Busta117
Last active August 29, 2015 14:22
Show Gist options
  • Save Busta117/00b4ccc9caf1e9a4ee94 to your computer and use it in GitHub Desktop.
Save Busta117/00b4ccc9caf1e9a4ee94 to your computer and use it in GitHub Desktop.
func setupBackButton(){
var count: Int? = navigationController?.viewControllers.count
if count > 0 && navigationItem.leftBarButtonItem == nil{
if !(navigationController?.viewControllers.first === self) {
self.navigationItem.leftBarButtonItem = HSAppearance.barButtonWithTitle("BACK", image:UIImage(named:"ArrowLeft"), target: self, action: "HSBackAction:")
}
}
}
el metodo para ese custom bar button:
class func barButtonWithTitle(title: String?, image:UIImage?, target: AnyObject?, action: Selector, rightAlign:Bool=false) -> UIBarButtonItem{
var titleColor:UIColor! = UIColor.whiteColor()
var but: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
but.frame = CGRectMake(0, 0, 70, 30);
but.backgroundColor = UIColor.clearColor()
but.setImage(image, forState: UIControlState.Normal)
but.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0)
but.titleLabel?.font = UIFont(name: CustomFont.CuprumRegular.rawValue, size: 15)
but.setTitleColor(titleColor, forState: UIControlState.Normal)
but.setTitle(title, forState: UIControlState.Normal)
but.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
but.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
if rightAlign {
but.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right
but.imageEdgeInsets = UIEdgeInsetsMake(0, but.frame.size.width - but.imageView!.width, 0, 0)
but.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, but.imageView!.width + 4)
}
// but.sizeToFit()
var barButton = UIBarButtonItem(customView: but)
return barButton
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment