iOS uilabel添加文字顏色,中劃線


-(NSAttributedString*)attributeWith:(NSString*)first second:(NSString*)second{//添加中劃線,文字顏色

    NSRange range1 = NSMakeRange(0, first.length);

    NSRange range2 = NSMakeRange(first.length+1, second.length-2);

    

    NSMutableAttributedString* astring = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",first,second]];

    NSDictionary* attributes = @{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName:[UIColor orangeColor],NSForegroundColorAttributeName:[UIColor blackColor] };

    [astring addAttributes:attributes range:range2];

    

    

    [astring addAttribute:NSStrikethroughStyleAttributeName value:@(  NSUnderlineStyleNone) range:range1];//

    

//    NSRange range = NSMakeRange(0, astring.length);

    [astring addAttribute:NSForegroundColorAttributeName value:YRedColor range:range1];//

    

    return astring;

    

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章