答案 0 :(得分:2)
这应该适用于iOS6及更高版本,使用referencedString:
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
答案 1 :(得分:0)
为什么不在文字很长的情况下使用UILabel和UITapGestureRecognizer,而且不需要任何额外的课程。
答案 2 :(得分:0)
检查一下。我希望这是你想要的。
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];