IPhone : UIButton title attributed text underlining for range of title doesn't work properly in iOS 8

on Wednesday, April 8, 2015

I wanted to underline range of text from UIButton title. The range is for last word of the UIButton title. Tried this in both the interface builder and code. Doesn't seems to be working properly in iOS 8 SDK. Xcode 6.2.


Here is the code snippet



NSRange textRange = [myButton.titleLabel.text rangeOfString:@"Sign Up"];
NSDictionary *underlineAttribute = @{
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)
};

NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:myButton.titleLabel.text];
[attributedText setAttributes:underlineAttribute range:textRange];

myButton.titleLabel.attributedText = attributedText;

0 comments:

Post a Comment