三十四 iOS修改导航栏文字按钮字体的大小

来源:互联网 发布:黑道圣4低配优化 编辑:程序博客网 时间:2024/06/05 20:09

昨天遇到个需求是通过导航栏的按钮去跳转到一个网页列表展示东西,需要按钮名称直接,简单。就用了文字按钮,

使用系统的按钮的话字体有些偏大不合适

就要修改字体大小,本人使用的第二种方法

两个方法:

1,在导航栏放置按钮,如果是右边记得让文字居右显示;

//    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
//    right.frame = CGRectMake(0, 0, 100, 50);
//    [right addTarget:self action:@selector(rightDeal) forControlEvents:UIControlEventTouchUpInside];
//    [right setTitle:@"查看XX" forState:UIControlStateNormal];
//    right.titleLabel.font = Font_CN(15);
//    right.backgroundColor = [UIColor redColor];
//    right.titleLabel.textAlignment = NSTextAlignmentRight;
//    [right setTitleColor:DB_Blue forState:UIControlStateNormal];
//    UIBarButtonItem *rightBut = [[UIBarButtonItem alloc]initWithCustomView:right];
//    self.navigationItem.rightBarButtonItem = rightBut;

代码中没有按钮文字居右的代码,这个自己找找就好

2,也是相对比较简单的一种方法

  UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"查看限额" style:UIBarButtonItemStylePlain target:self action:@selector(rightDeal)];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
//    [self.navigationItem.rightBarButtonItem setTintColor:MainColor];
    
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:Font_CN(14), NSFontAttributeName, nil] forState:UIControlStateNormal];

Font_CN(14)  为字体大小可以自己设置的


阅读全文
1 0
原创粉丝点击