一:自定义titleHeadView ,
titleHeadView.h中:
@property(nonatomic, assign) CGSize intrinsicContentSize;
headView = [[titleHeadView alloc]init];
headView.intrinsicContentSize = CGSizeMake(Screen_Width-100, 28);
headView.translatesAutoresizingMaskIntoConstraints = false;
headView.backgroundColor = [UIColor clearColor];
searchtextFiled = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, Screen_Width-100, 28)];
searchtextFiled.placeholder = @"请输入搜索关键字";
searchtextFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
searchtextFiled.textColor = [UIColor colorWithHexString:@"969696"];
searchtextFiled.font = [UIFont systemFontOfSize:13];
searchtextFiled.borderStyle = UITextBorderStyleRoundedRect;
searchtextFiled.backgroundColor = [UIColor whiteColor];
searchtextFiled.returnKeyType = UIReturnKeySearch;
searchtextFiled.delegate = self;
[headView addSubview:searchtextFiled];
self.navigationItem.titleView = headView;
看不明白的可以加我主页的QQ。