如果标题很长,在UIButton的末端设置点号

问题描述:

我有一个UIButton,我想用长文本为它设置标题。如:@ “在UIButton的结束点设置如果标题是漫长的”如果标题很长,在UIButton的末端设置点号

我用:

[btn setTitle:@"set dots at the end of UIButton if title is long" forState:UIControlStateNormal]; 

- > BTN的出现: “集点......在”

现在我想显示“设置点...”

我该怎么办?

谢谢大家!

+0

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instp/UIButton/titleLabel – 2015-02-10 03:49:30

+0

https://developer.apple.com/library /ios/documentation/Cocoa/Reference/ApplicationKit/Classes/NSParagraphStyle_Class/index.html#//apple_ref/doc/c_ref/NSLineBreakMode – 2015-02-10 03:50:49

+0

NSLineBreakByTruncatingTail 显示该行,以便开头适合容器,并在该行的结尾由省略号字形表示。 – 2015-02-10 03:51:17

令人惊讶的是,现在还没有关于按钮标签的文章。

简单地做:

[btn setTitle:@"set dots at the end of UIButton if title is long" forState:UIControlStateNormal]; 
btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail; 

访问按钮的titleLabel允许您调整时直接UIButton方法不存在需要按钮的标签属性。

+0

是的@rmaddy,我做的一样,它运作良好:)谢谢! – Bkillnest 2016-04-07 01:27:17

在选择按钮后的故事板转到属性检查器并将lineBreak属性设置为截断尾部。

enter image description here