2012-10-18 37 views
0

想知道如何從上向下設置UIButton標題標籤中的文字。如何設置UIButton標題標籤自頂向下

文字是 「按我」 跨

會喜歡展示

" 
p 
r 
e 
s 
s 

m 
e 
" 

我這樣做

CGAffineTransform newTransform = CGAffineTransformMakeRotation(90 * (M_PI/180)); 
    self.activeButton.transform = newTransform; 

,但它只是改變了按鈕的方向不是文本

+0

,我認爲最好使用button.so來設置圖像,就像你想要的一樣。 –

回答

3

將文本旋轉爲垂直不同於將每個字母寫入單獨的行,whi我從你的問題中收集到的是你的意圖。

要做到這一點,您需要在單獨的一行中實際編寫每個字母!您可以在界面構建器的文本字段中按住Alt/Option,同時按下Enter鍵,在UIButton文本中創建新行。請注意,這必須是「實用工具」面板中的文本字段屬性,如果通過雙擊按鈕編輯文本,則不能添加新行。

完成此操作後,將「換行符」模式更改爲「字符換行」或「字換行」,以便顯示多行。

編輯:我意識到,你可能會嘗試與你的代碼按鈕的工作,所以我寫了這一塊應該轉換一個普通按鈕的文本被垂直間隔,信信:

// Create a temporary NSString to store the new formatted text string 
// Set it to the first character so we can have a simple loop from the second to the last character 
NSString *newText = [NSString stringWithFormat:@"%C",[button.titleLabel.text characterAtIndex:0]]; 
for(int i=1;i<button.titleLabel.text.length;i++) { 
    // Format newText to include a newline and then the next character of the original string 
    newText = [NSString stringWithFormat:@"%@\n%C",newText,[button.titleLabel.text characterAtIndex:i]]; 
} 
// We must change the word wrap mode of the button in order for text to display across multiple lines. 
button.titleLabel.lineBreakMode = NSLineBreakByCharWrapping; 
// .. and for an unknown reason, the text alignment needs to be reset. Replace this if you use something other than center alignment. 
button.titleLabel.textAlignment = NSTextAlignmentCenter; 
// newText now contains the properly formatted text string, so we can set this as the button label 
[button setTitle:newText forState:UIControlStateNormal];