2014-12-02 65 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