```
UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
btn.backgroundColor =[UIColor greenColor];
btn.frame = CGRectMake(50, 100, 200, 60);
[btn setTitle:@"fengfeng\nNewfengfeng" forState:(UIControlStateNormal)];
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
btn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
btn.titleLabel.numberOfLines = 2;
[self.view addSubview:btn];
```
重点在于在两行标题中间加\n
之前我总是往button上加两个label,但是这样的话按钮的点击事件就会失效,而且处理起来非常的麻烦。这个方法帮我解决了很多问题。
网友评论