Thứ Tư, 8 tháng 7, 2015

iOS: navigationBar

Change the Navigation Bar color in iOS 7 or later
Link: http://stackoverflow.com/a/18929980
Objective-C
// iOS 7.0 or later   
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    self.navigationController.navigationBar.translucent = NO;
Swift

    self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
    self.navigationController?.navigationBar.translucent = false

Add button UIBarButtonItem to left or right of navigationBar

let leftButton = UIBarButtonItem(title: "Left", style: .Plain, target: self, action: "clickLeft:")
let rightButton = UIBarButtonItem(title: "Right", style: .Plain, target: self, action: "clickRight:")
 
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationItem.setLeftBarButtonItems([leftButton] as [AnyObject], animated: true)
self.navigationItem.setRightBarButtonItems([rightButton] as [AnyObject], animated: true) 

Add button with image

var btn = UIButton(frame: CGRect(x: 0, y: 0, width: w, height: h))
btn.setImage(UIImage(named: "btn-img"), forState: UIControlState.Normal)
btn.addTarget(self.navigationController, action: Selector("clickButtonWithImage:"), forControlEvents:  UIControlEvents.TouchUpInside)
var item = UIBarButtonItem(customView: btn)
self.navigationItem.leftBarButtonItem = item

Continue updating ...
- Comments

0 nhận xét:

Đăng nhận xét