1. Modify Navigationbar
Navigationbar actually has three sub-views, Leftbarbuttonitem,rightbarbuttonitem, and Titleview.
1.1 Method One: Alloc a uinavigationbar, and give alloc out of the Navigationbar set button and view, and the system Navigationbar no obvious difference. If you want to add a navigationbar when there is no navigationcontroller management, this method is still possible ... However, when added to a scrollable view (such as TableView), it scrolls as The view scrolls and is not recommended, and the code is not posted.
1.2 Method Two: Modify the system Uinavigationbar Leftbarbuttonitem,rightbarbuttonitem, and Titleview
Set the left button uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] initwithtitle:@ "Ieft" style: Uibarbuttonitemstyledone target:self Action: @selector (Test)]; Self.navigationItem.leftBarButtonItem = Leftitem;
Set Right button
Uibarbuttonitem *rightitem = [[Uibarbuttonitem alloc] initwithtitle:@ "button" Style:uibarbuttonitemstyledone target: Self action: @selector (Test)]; Self.navigationItem.rightBarButtonItem = Rightitem;
Modify Titleview font Color nsdictionary *dic = [nsdictionary dictionarywithobject:[uicolor Redcolor] Forkey: Nsforegroundcolorattributename]; Self.navigationController.navigationBar.titleTextAttributes = Dict;
The translucent effect of the navigationbar can be achieved by
Self.navigationController.navigationBar.translucent = NO;
Shut down.
1.3 Hide Navigationbar, custom view instead of Navigationbar
This method is simple and rude. Strong customization, a common UIView, can be placed in any position you want any control, set a variety of colors.
The problem in the layout with the child view needs to be aware that the starting Y value is 64 (status bar + Navigationbar 44). When you have too many views, it's a very difficult thing to do.
Self.navigationController.navigationBarHidden = NO; Self.headerview = [[[NSBundle Mainbundle] loadnibnamed:@ "Headerview" Owner:nil Options:nil]lastobject]; [Self.headerView.menuButton addtarget:self Action: @selector (ShowMenu:) forControlEvents: UIControlEventTouchUpInside]; Self.headerView.frame = CGRectMake (0, Kscreenw, a); [Self.view AddSubview:self.headerView];
1.4 Adding a custom view to the Titleview
Instead of hiding the navigationbar, and then adding the custom view to the Titleview, the advantage is that you don't have to consider the coordinate problem. It is as simple as the navigationbar of the system and adds customization. The only thing that's not titleview is that the frame is not the whole navigationbar, it doesn't look uniform, and the workaround is to adjust the navigationbar background color to the same as the custom view.
Self.navigationController.navigationBarHidden = NO; Headerview *headerview = [[[NSBundle Mainbundle] loadnibnamed:@ "Headerview" Owner:nil Options:nil]lastobject]; Headerview.frame = CGRectMake (0, Kscreenw, a); Self.navigationController.navigationBar.translucent = NO; Self.navigationitem Sethidesbackbutton = YES; Navigationbar color is the same as Headerview color self.navigationController.navigationBar.backgroundColor = [Uicolor Whitecolor]; Self.navigationItem.titleView = Headerview;
iOS Custom NavBar