2012-10-18 38 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];