在iOS中,将UIlabel的字体加上下划线,可以通过如下代码实现:
/*------ 下划线文字 --------*/
UILabel * underLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 280, 300, 67)];
underLineLabel.numberOfLines = 0;
underLineLabel.backgroundColor = [UIColor cyanColor];
NSMutableAttributedString * contentString = [[NSMutableAttributedString alloc] initWithString:@"zgedshjkfhvuicfhdguigcuivghufid"];
NSRange contentRange = {0,[contentString length]};
[contentString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleDouble] range:contentRange];
underLineLabel.attributedText = contentString;
[self.view addSubview:underLineLabel];
NSUnderlineStyleDouble可以换为NSUnderlineStyleSingle