发布于 2014-02-07 19:42:41
使用attributedString,这对iOS6和更高版本应该是有效的:
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"yourTextButton"];
[attrStr addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, [attrStr length])];
[yourButton setAttributedTitle:attrStr forState:UIControlStateNormal];
[[yourButton titleLabel] setNumberOfLines:0];//Multiple Lines发布于 2014-02-07 19:34:58
当文本这么长并且不需要任何额外的类时,为什么不使用UILabel和UITapGestureRecognizer呢?
发布于 2014-02-07 20:04:18
看看这个。我希望这是你想要的。
NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"Tap here...."];
[titleString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [titleString length])];
[titleString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, [titleString length])];
[_button setAttributedTitle: titleString forState:UIControlStateNormal];https://stackoverflow.com/questions/21626635
复制相似问题