2015-01-14 24 views
0

是否可以在不使用圖像的情況下通過文字創建按鈕?如何通過UIButton創建一個罷工?

我知道這是可能給它做一個UILabel

NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"]; 
[attributeString addAttribute:NSStrikethroughStyleAttributeName 
         value:@2 
         range:NSMakeRange(0, [attributeString length])]; 
+3

[' - [UIButton的setAttributedTitle:forState:]'](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class /index.html#//apple_ref/occ/instm/UIButton/setAttributedTitle:forState :) –

回答

0

你需要設置標題使用setAttributedTitle:forState:通過您創建的屬性串的按鈕。

0

您可以嘗試

[button setAttributedTitle:attributeString forState:UIControlStateNormal]; 
[button setAttributedTitle:attributeString forState:UIControlStateHighlighted] 
0
let attributes = [NSStrikethroughStyleAttributeName : 1] 
    let title = NSAttributedString(string: "YOUR STRING", attributes: attributes) 

    button.setAttributedTitle(title, forState: .Normal) 
相關問題