Multiple lines with underline in UIButton header in iOS-5

I want to create an underlined button link after an image in iOS. enter image description here

I already used UIUnderlineButton

therefore it gives me the following result.

enter image description here

please help me achieve the underlined button, for example, the 1st image.

+4
source share
3 answers

This should do the trick for iOS6 and above using the String attribute:

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
+2
source

Why don't you use UILabel and UITapGestureRecognizer when your text is long and you don't need any additional classes.

0
source

. , , .

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];
0

Source: https://habr.com/ru/post/1525779/


All Articles