Ios 在iPhone 6+中不起作用的属性文本中加下划线;
我想创建一个返回属性文本的方法 这是我正在使用的代码Ios 在iPhone 6+中不起作用的属性文本中加下划线;,ios,iphone,nsattributedstring,Ios,Iphone,Nsattributedstring,我想创建一个返回属性文本的方法 这是我正在使用的代码 - (NSAttributedString *)getUnderlineAttributedStringForText:(NSString *)strWholeString andTextToHaveLink:(NSString *)strLink TextColor:(UIColor *)textColor LinkColor:(UIColor *)linkColor withFont:(UIFont*)font { NSRange st
- (NSAttributedString *)getUnderlineAttributedStringForText:(NSString *)strWholeString andTextToHaveLink:(NSString *)strLink TextColor:(UIColor *)textColor LinkColor:(UIColor *)linkColor withFont:(UIFont*)font {
NSRange stringRange = NSMakeRange(0, strWholeString.length);
NSRange linkRange = [strWholeString rangeOfString:strLink];
NSLog(@"String Link :: %@",[strWholeString substringWithRange:linkRange]);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:strWholeString];
// Paragraph Style
NSMutableParagraphStyle *paragrapStyle = NSMutableParagraphStyle.new;
paragrapStyle.alignment = NSTextAlignmentLeft;
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:stringRange];
[attributedString addAttribute:NSForegroundColorAttributeName value:textColor range:stringRange];
[attributedString addAttribute:NSFontAttributeName value:font range:stringRange];
[attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger: NSUnderlineStyleSingle] range:linkRange];
[attributedString addAttribute:NSForegroundColorAttributeName value:linkColor range:linkRange];
return attributedString;
}
// This is how I call the method
[btnTermOfUse setAttributedTitle:[self getUnderlineAttributedStringForText:@"By signing up you agree to the Terms of Use" andTextToHaveLink:@"Terms of Use" TextColor:[UIColor darkGrayColor] LinkColor:[UIColor orangeColor] withFont:[UIFont systemFontOfSize:16]] forState:UIControlStateNormal];
此代码在除6+以外的所有设备中都能正常工作
编辑
-在6+中,仅下划线不显示链接文本的文本颜色变化。
我可以在iphone6或5S中看到下划线
有人知道这件事吗
我知道已经有很多与此相关的问题,但它们对我没有帮助,所以我在这里写作。找到了一个黑客!!:(
您应该在设置文本之前写这行
[btnTermOfUse titleLabel].numberOfLines = 0;
这将向您展示设备上的线路。那么6+有什么问题?请查看我的编辑在模拟器上或仅在设备上?它在模拟器上工作正常。我尝试在设备和模拟器上运行,但得到相同的结果。现在它在模拟器上工作,但在设备上仍然不工作