iOS/Objective C

NSString UILabel 한줄 취소선

CoCoE 2016. 2. 4. 15:51

- (void) setLine:(UILabel*)label

{

    //글자 세팅

    NSString* str = @"Hello World";

    NSMutableAttributedString* attStr = [[NSMutableAttributedString alloc] initWithString:str];

    

    NSRange range1 = [str rangeOfString:@"Hello"];//범위

    

    //취소선 긋기

    [attStr addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle), NSStrikethroughColorAttributeName:[UIColor redColor]} range:range1];

    

    [label setAttributedText:attStr];

}