2014-12-02 40 views
1

我测试下面的代码:长UIButton的标题标签截断的中心,而不是右边

username = @"addagkagalkjagjalggxxaklgjagjglkjag"; 

NSString *fullUsername = [NSString stringWithFormat:@"%@%@", @"@", username]; 

UIButton *usernameButton = [UIButton buttonWithType:UIButtonTypeSystem]; 
[usernameButton setTitle:fullUsername forState:UIControlStateNormal]; 

usernameButton.frame = CGRectMake(100.0, 10.0, 215.0, 25.0); 

最终结果截断和省略号在标签的中心。我最终需要它,但是我必须为此设置哪些属性?

回答

4
usernameButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail; 
+0

https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIButton_Class/index.html#//apple_ref/occ/instp/UIButton/lineBreakMode – Flexicoder 2014-12-02 07:56:51

+0

正是我想要的,谢谢。 – cdub 2014-12-02 07:57:03