iOS导航条和工具条

来源:互联网 发布:淘宝基础班导航条全屏 编辑:程序博客网 时间:2024/06/05 02:08

设置导航条上方是否留出(信号,电池的空隙)

self.navigationController.navigationBar.clipsToBounds =YES;


导航条的的样式:navigationBar.barStyle

self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

    

导航条的背景图(基于导航控制器的,不会压缩图片):navigationBar setBackgroundImage...

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"people_caoying.png"] forBarMetrics:UIBarMetricsDefault];

    

自定义导航条的左右文字按钮:UIBarButtonItem

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"左按钮" style:UIBarButtonItemStylePlain target:self action:@selector(clickLeft)];

    

系统自带的导航条的左右文字按钮(一大堆:编辑,保存,返回.....)

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];

    

设置当前视图的控制器的返回按钮,在下个界面生效

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"gs" style:UIBarButtonItemStylePlain target:self action:nil];

    

隐藏返回按钮

self.navigationItem.hidesBackButton = YES;

    

导航栏的左右图片按钮

UIButton *buttonRight = [UIButton buttonWithType:UIButtonTypeCustom];

buttonRight.frame = CGRectMake(0, 0, 40, 40);

[buttonRight setBackgroundImage:[UIImage imageNamed:@"press.png"] forState:UIControlStateNormal];

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonRight];

    

导航栏的视图标题:navigationItem.titleView(视图标题)(会压缩图片,全部显示上去)

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 40)];

imageView.image = [UIImage imageNamed:@"people_caoying.png"];

self.navigationItem.titleView = imageView;

    

同时添加多个导航条按钮

UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithTitle:@"第一" style:UIBarButtonItemStyleDone target:self action:nil];

UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithTitle:@"第二" style:UIBarButtonItemStyleDone target:self action:nil];

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 40)];

view.backgroundColor = [UIColor orangeColor];

UIBarButtonItem *item3 = [[UIBarButtonItem alloc]initWithCustomView:view];

self.navigationItem.leftBarButtonItems = @[item1, item2, item3];

    

为导航栏添加视图标题titleview

UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];

lable.text = @"自定义";

lable.textColor = [UIColor redColor];

lable.backgroundColor = [UIColor yellowColor];

lable.textAlignment = NSTextAlignmentCenter;

self.navigationItem.titleView = lable;


统一修改toolbar元素颜色

[[UIToolbar appearance]setTintColor:[UIColor yellowColor]];


toolbar显示

self.navigationController.toolbarHidden =NO;


修改toolbar的风格

self.navigationController.toolbar.barStyle = UIBarStyleBlack;


创建多个UIBarButtonItem 添加到工具栏

UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"红色" style:UIBarButtonItemStylePlain target:self action:nil];

UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

UIBarButtonItem *item4 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

self.toolbarItems =@[item,item2,item4];


1 0
原创粉丝点击