如何设置UIBUTTON TITLELABEL TOPDOWN



想知道如何在自上而下的uibutton标题标签中设置文本。

文本是"按我"

想显示

"
p
r
e
s
s
m
e
"

我做了这个

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

,但它仅更改按钮方向而不是文本

旋转文本要垂直与在单独的行上写下每个字母不同,这是我从问题中收集到的意图。

要这样做,您需要在单独的行上实际写每个字母!您可以通过在接口构建器中的文本字段中按住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];

最新更新