[Swift]UINavigationBarのカスタマイズ方法について
0
iQi - 面白いアプリを開発中
let navBar = UINavigationBar.appearance()
let navBarBGColor = UIColor(red: 249/255, green: 85/255, blue: 160/255, alpha: 0.5);
navBar.barTintColor = navBarBGColor;
let barShadow: NSShadow = NSShadow()
barShadow.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
barShadow.shadowOffset = CGSize(width: 0, height: 1)
let attributes:[String:AnyObject] = [
//NSFontAttributeName:UIFont(name: "Electrolize", size: 24.0)!,
NSForegroundColorAttributeName:UIColor(red: 255, green: 255, blue: 255, alpha: 1),
NSShadowAttributeName:barShadow,
]
navBar.titleTextAttributes = attributes
let editBtn = UIButton(type: UIButtonType.Custom)
editBtn.frame = CGRectMake(0, 0, 30, 30)
editBtn.titleLabel?.setFontSize(26)//21
editBtn.addTarget(self, action: "onClickEditBarButton:", forControlEvents: UIControlEvents.TouchUpInside)
editBtn.setBootstrapIcon(FAIcon.faedit, beforeTitle: true)
let editBarBtn = UIBarButtonItem(customView: editBtn)
self.navigationItem.setRightBarButtonItem(editBarBtn, animated: true)
let refreshBtn = UIButton(type: UIButtonType.Custom)
refreshBtn.frame = CGRectMake(0, 0, 30, 30)
refreshBtn.titleLabel?.setFontSize(26)//21
refreshBtn.addTarget(self, action: "onClickRefreshBarButton:", forControlEvents: UIControlEvents.TouchUpInside)
refreshBtn.setBootstrapIcon(FAIcon.farefresh, beforeTitle: true)
let refreshBarBtn = UIBarButtonItem(customView: refreshBtn)
self.navigationItem.setLeftBarButtonItem(refreshBarBtn, animated: true)
self.navigationItem.hidesBackButton = true
let negativeSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
negativeSpacer.width = -6.0
self.navigationItem.leftBarButtonItems = [negativeSpacer, refreshBarBtn]
self.navigationItem.rightBarButtonItems = [negativeSpacer, editBarBtn]