首页 > 代码库 > navigationController基本设置

navigationController基本设置

//    设置导航栏的文字
    
self.navigationItem.title = @"功效";


//    设置导航栏的颜色
    
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];

//    设置导航栏上字体颜色
    [
self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeNamenil]];

//    设置导航栏不透明
    self.navigationController.navigationBar.translucent = NO;
 
 
//设置左侧返回按钮颜色
    
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
 
//设置右侧取消按钮的颜色
    
self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
 
导航控制器也可添加一下其他控件,如搜索栏,分段视图等
例:

mySearchBar = [[UISearchBaralloc] initWithFrame:CGRectMake(0, 25, 50, 30)];

    mySearchBar.delegate = self;

    mySearchBar.placeholder = @"请输入查询的蔬菜、水果等的品名";//  设置占位符

   

    searchDisplayController = [[UISearchDisplayControlleralloc] initWithSearchBar:mySearchBarcontentsController:self];

    searchDisplayController.active = NO;

    self.navigationItem.titleView = mySearchBar;//  添加到导航控制器上

    

    [mySearchBarrelease];

    [searchDisplayControllerrelease];

运行效果如下: