代码语言:javascript复制
-(BaseNavigationController*)setTabBarItemWithRootVC:(id)vc Image:(NSString*)imgName SelectedImage:(NSString*)selectedImg
{
BaseNavigationController *nav = [[BaseNavigationController alloc] init];
[nav.tabBarItem setImage:[[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[nav.tabBarItem setSelectedImage:[[UIImage imageNamed:selectedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[nav.tabBarItem setImage:[[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[nav.tabBarItem setSelectedImage:[[UIImage imageNamed:selectedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
returnnav;
}
1.设置按钮操作
代码语言:javascript复制//返回按钮
UIBarButtonItem * buttonItem = [[UIBarButtonItem alloc]initWithTitle:nil style:UIBarButtonItemStyleDone target:self action:@selector(backIndex)];
[buttonItem setImage:[UIImage imageNamed:@"返回"]];
self.navigationItem.leftBarButtonItem= buttonItem;
//导航栏标题
self.navigationItem.title = @"个人中心";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[XUtil hexToRGB:@"333333"],NSFontAttributeName:[UIFont systemFontOfSize:16]}];
//左键
UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(backIndex) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
self.navigationItem.leftBarButtonItem = leftItem;
//导航栏标题
self.navigationItem.title = @"单词详解";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[XUtil hexToRGB:@"2E2F33"],NSFontAttributeName:[UIFont systemFontOfSize:16]}];
//右键
UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[moreBtn setTitle:@"更多" forState:UIControlStateNormal];
[moreBtn setTitleColor:UIColorFromRGB(0xBDBEBF) forState:UIControlStateNormal];
moreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[moreBtn addTarget:self action:@selector(quci) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:moreBtn];
self.navigationItem.rightBarButtonItem = rightItem;
//把view添加到nav
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:barView];
2.如何找到searchBar中的UItextField并修改
代码语言:javascript复制 searchView.frame = CGRectMake(0, kStatusBarHeight Main_Screen_Width * 10 / 640, Main_Screen_Width * 470 / 640, kTopBarHeight);
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 284 * adjustWidth, kTopBarHeight)];
// ViewRadius(searchBar,8.0);
searchBar.delegate = self;
searchBar.barTintColor = [UIColor clearColor];
UITextField* searchTextField = [[[searchBar.subviews firstObject] subviews] lastObject];
searchTextField.dk_textColorPicker = DKColor_TEXTCOLOR_TITLE;
searchTextField.font = font14;
searchBar.searchBarStyle = UISearchBarStyleMinimal;
searchBar.barStyle = UIBarStyleDefault;
[searchBar.layer setBorderWidth:1.0];
searchBar.layer.borderColor = [[UIColor clearColor] CGColor];
searchBar.backgroundColor=[UIColor clearColor];
searchBar.placeholder = @"请输入关键字名称";
[searchView addSubview:searchBar];
[searchBar becomeFirstResponder];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchView];