1.设置文字
[btn setTitle: @"search" forState: UIControlStateNormal];
*注意:用 btn.titleLabel.text = @"xxx" 并没有用
2.设置字体
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
3.设置字体颜色
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
注意:不要用:
[btn.titleLabel setTextColor:[UIColorblackColor]]; btn.titleLabel.textColor=[UIColor redColor];
4.圆形按钮
//前提:按钮要设置为正方形 btn.layer.cornerRadius = wireBtn.bounds.size.width/2; btn.layer.masksToBounds = wireBtn.bounds.size.width/2;
5.图片按钮
[deviceImageBtn setImage:[UIImage imageNamed:@"icobarico_4.png"] forState:UIControlStateNormal];
6.Button点击事件传参:
1.设置tag:btn.tag = 101;
2.使用如下:
-(void)circleBtnClicked:(UIButton*)sender{ switch (sender.tag) { case 101: { UIStoryboard *wireboard = [UIStoryboard storyboardWithName:@"MyDevice" bundle:nil]; LoginController *wirevc = [wireboard instantiateViewControllerWithIdentifier:@"my_device_home"]; [self.navigationController pushViewController:wirevc animated:YES]; } break; case 2: break; } }
7.设置带文字图片呢按钮:
1.http://www.jianshu.com/p/3052a3b14a4e
2.http://blog.csdn.net/u011462377/article/details/48595485
8.按钮内文字换行:
_parental_control_btn.titleLabel.textAlignment = NSTextAlignmentCenter; _parental_control_btn.titleLabel.numberOfLines = 0;
如果有必要,也可以同时在Localizable.strings的value里添加\n,显示效果会有不同。