將文本旋轉爲垂直不同於將每個字母寫入單獨的行,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];
,我認爲最好使用button.so來設置圖像,就像你想要的一樣。 –