我想在标签上添加下划线。为此,我使用了以下代码。我正在使用自定义字体:
headingLbl.font=[UIFont fontWithName:GZFont size:20.0f];
NSMutableAttributedString *gpsSearch = [[NSMutableAttributedString alloc] initWithString:@"GPS Search"];
[gpsSearch addAttribute:(NSString*)kCTUnderlineStyleAttributeName
value:[NSNumber numberWithInt:kCTUnderlineStyleSingle]
range:(NSRange){0,[gpsSearch length]}];
self.headingLbl.attributedText = gpsSearch;
self.headingLbl.textColor = [UIColor blackColor];
最佳答案
使用下面的代码。这对我有用。
NSMutableAttributedString *gpsSearch = [[NSMutableAttributedString alloc] initWithString:@"GPS Search"];
[gpsSearch addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:NSUnderlineStyleSingle]
range:(NSRange){0,[gpsSearch length]}];
如果不起作用,则问题可能出在您的自定义字体上
关于ios - 标签下划线不显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20677537/