UINavigationcontrollerBar,UIbarButtonItem按钮以及backButton背景及背景颜色改变



(作者比较懒,喜欢用iOS自带属性修饰控件,喜欢自定义或重写的朋友请绕行)
一.自定义navigation外观
先准备背景图片navigation
 UIImage *image = [UIImageimageNamed:@"navigation"];

    //改变navigationcontroller背景(青色)

    [self.navigationController.navigationBar  setBackgroundImage:imageforBarMetrics:UIBarMetricsDefault];

    UIBarButtonItem *back = [[UIBarButtonItem  alloc]initWithTitle:@"back"style:UIBarButtonItemStyleBorderedtarget:self  action:@selector(back:)];

    //backButton背景颜色(back按钮背景黄色)

    back.tintColor = [UIColor  yellowColor];

    self.navigationItem.backBarButtonItem = back;


    UIBarButtonItem *right = [[UIBarButtonItem  alloc]initWithTitle:@"next"  style:UIBarButtonItemStyleBordered  target: self  action:@selector(next:)];

    //改变right背景颜色(next按钮背景绿色)

    right.tintColor = [UIColor greenColor];

  self.navigationItem.rightBarButtonItem = right;


  //    NSArray *fontsArr = [UIFont familyNames];//打印所有字体

    //navigation标题(棕色brownColor)(字典依次为标题(餐饮,种类)字体颜色,阴影颜色,阴影范围,字体,字体大小)

    [self.navigationController.navigationBarsetTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorbrownColor],UITextAttributeTextColor, [UIColorcolorWithRed:0 green:0 blue:0alpha:0.8],UITextAttributeTextShadowColor,[NSValuevalueWithUIOffset:UIOffsetMake(0.5, 0.5)],UITextAttributeTextShadowOffset,[UIFontfontWithName:@"Times New Roman"size:24.0f],UITextAttributeFont, nil]];

      //定制应用中所有导航栏有barButttonItem按钮  appearance(字典依次为标题(next,back)字体颜色,阴影颜色,阴影范围,字体,字体大小)

    [[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:

        [UIColor redColor ],UITextAttributeTextColor,[UIColorcolorWithRed:0 green:0 blue:0alpha:0.8],UITextAttributeTextShadowColor,[NSValuevalueWithUIOffset:UIOffsetMake(1.5, 1.5)],UITextAttributeTextShadowOffset,[UIFontfontWithName:@"Times New Roman"size:20],UITextAttributeFont, nil]forState:UIControlStateNormal ];

有图有真相:(为了显示阴影效果偏移量UIOffsetMake(1.5, 1.5)比较,自己调小即可,红色为按钮标题颜色,黑色(alpha:0.8)为阴影)



二.图片+手势也可完成navigationController同样功能
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值