昨天遇到个需求是通过导航栏的按钮去跳转到一个网页列表展示东西,需要按钮名称直接,简单。就用了文字按钮,
使用系统的按钮的话字体有些偏大不合适
就要修改字体大小,本人使用的第二种方法
两个方法:
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) 为字体大小可以自己设置的