设置UITextView,UILabel 中的文字加下划线


//添加下划线-(NSAttributedString*) getAttributedString:(NSAttributedString*) attributedString isUnderline:(BOOL) isUnderline{ NSNumber *valuUnderline = [NSNumbernumberWithBool:isUnderline]; NSRange rangeAll = NSMakeRange(0, attributedString.string.length); NSMutableAttributedString *as = [attributedString mutableCopy]; [as beginEditing]; [as addAttribute:NSUnderlineStyleAttributeNamevalue:valuUnderline range:rangeAll]; [as endEditing]; return as;}


使用

textView.attributedText = [self getAttributedString:_mainTextView.attributedText isUnderline:YES];label.attributedText = [self getAttributedString:_mainTextView.attributedText isUnderline:YES];