UI之导航栏属性、按钮及样式、属性传值

导航栏标题、颜色、按钮文字、文字颜色、样式、导航栏上按钮样式等的设置


先创建名为 OneViewController、TwoViewControllerThreeViewController的视图控制器,并设置其导航栏标题及背景颜色以作页面切换时的区分

    //导航栏上显示的标题
    self.navigationItem.title = @"stupid";
    //默认导航栏是YES透明的,NO不透明
    self.navigationController.navigationBar.translucent = YES;
    //导航栏上按钮颜色
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    //导航栏样式
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    //导航栏颜色
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:50.0/255.0f green:250.0/255.0f blue:120.0/255.0f alpha:1.0];
    //导航栏上还有navigationItem ,initWithBarButtonSystemItem初始化按钮样式
    UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(leftAction:)];
    //把按钮left设置为navigationItem的左边按钮
    self.navigationItem.leftBarButtonItem = left;
    //使用自定义视图设置button
    UIButton *rightbt = [UIButton buttonWithType:UIButtonTypeCustom];
    rightbt.frame = CGRectMake(0, 0, 44, 44);
    [rightbt setTitle:@"next" forState:UIControlStateNormal];
    [rightbt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [rightbt addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    //把创建的按钮设置为UIBarButtonItem初始化时的自定义视图
    UIBarButtonItem *rightBarbt = [[UIBarButtonItem alloc]initWithCustomView:rightbt];
    //把rightBarbt设置为navigationItem右侧按钮
    self.navigationItem.rightBarButtonItem = rightBarbt;

- (void)leftAction:(UIBarButtonItem *)bar{
    ThreeViewController *three = [[ThreeViewController alloc]init];
    [self.navigationController pushViewController:three animated:YES];
}

属性传值:

第一步:在TwoViewController.h中设置一个字符串类型的属性

@property(nonatomic,retain)NSString *str;

第二步:把导航栏的标题设置为self.str
 self.navigationItem.title = self.str;

- (void)rightAction:(UIBarButtonItem *)bar{
    TwoViewController *two = [[TwoViewController alloc]init];

第三步:等号两边内容一致才能完成属性传值
    two.str = self.tf.text;

    [self.navigationController pushViewController:two animated:YES];
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值