Custom Navigationbar
Functional requirements in the Navigationbar to add a search box, and its position to put forward a request, the system Titleview can not be satisfied, so consult the data, rewrite the Titleview
TitleView.h file, overriding Titleview inheritance UIView
#import <UIKit/UIKit.h>
@interface titleview:uiview
@end
TITLEVIEW.M file, overriding the frame of its parent class
#import "TitleView.h"
@implementation titleview
-(Instancetype) initWithFrame: (CGRect) frame {
self = [ Super Initwithframe:frame];
if (self) {
} return
self;
}
-(void) Setframe: (CGRect) frame {
[super Setframe:cgrectmake (0, 0, Self.superview.frame.size.width, Self.superview.bounds.size.height)];
}
@end
refer to where you need to use
//Here is the reason to put leftbarbuttonitem title = @ "", Set to prevent the interface from Pushviewcontroller from the previous layer: or from the interface popviewcontrolleranimated: is to display the system's own return arrows Uibarbuttonitem * Backbuttonitem = [
Uibarbuttonitem alloc] init];
[Backbuttonitem settitle:@ "];
Self.navigationItem.leftBarButtonItem = Backbuttonitem;
_titleview = [[Titleview alloc] Initwithframe:cgrectmake (0, 0, Screen_width, 44)];
_titleview.backgroundcolor = [Uicolor blackcolor]; Self.navigationItem.titleView = _titleview;