iOS 개발 OC - 텍스트 속성 Attributes 사용

4140 단어
그냥 간단하게 필기하는 거예요.
텍스트 속성
NSFontAttributeName                    //      
NSParagraphStyleAttributeName          //      
NSForegroundColorAttributeName         //       
NSBackgroundColorAttributeName         //       
NSLigatureAttributeName                //      
NSKernAttributeName                    //         
NSStrikethroughStyleAttributeName      //        
NSUnderlineStyleAttributeName          //        
NSStrikethroughColorAttributeName      //        
NSStrokeColorAttributeName             //           
NSStrokeWidthAttributeName             //         
NSShadowAttributeName                  //      
NSTextEffectAttributeName              //         
NSAttachmentAttributeName              //      
NSLinkAttributeName                    //     
NSBaselineOffsetAttributeName          //       
NSUnderlineColorAttributeName          //        
NSObliquenessAttributeName             //      
NSExpansionAttributeName               //       (    )
NSWritingDirectionAttributeName        //         
NSVerticalGlyphFormAttributeName       //         

두 번째 사용 예
쓰기 방식
    //   
    NSString * helloStr = @"hello word";
    NSMutableAttributedString * mString = [[NSMutableAttributedString alloc] initWithString: helloStr];
    
    //  1
    NSDictionary * dic = @{NSFontAttributeName :[UIFont fontWithName:@"Helvetica-Bold" size:20],NSForegroundColorAttributeName:[UIColor redColor],};
    [mString addAttributes:dic range:NSMakeRange(0, 3)];
  
    //  2
    [mString addAttribute: NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 4)];
    [mString addAttribute: NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:20] range:NSMakeRange(0, 7)];

    label.attributedText = mString;

    //   
    label.attributedText = [[NSAttributedString alloc]initWithString: helloStr attributes:dic];

글꼴 단락
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
    style.alignment = NSTextAlignmentLeft;
    style.lineSpacing = 5;
    //           
    style.firstLineHeadIndent = 20;
    //           
    style.headIndent = 2;
    [mString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, str.length)];
    //   
    [mString addAttribute:NSKernAttributeName value:@1.5 range:NSMakeRange(0, str.length)];

    //NSDictionary * dic = @{NSFontAttributeName :[UIFont fontWithName:@"Helvetica-Bold" size:20],NSForegroundColorAttributeName:[UIColor redColor],NSParagraphStyleAttributeName:style,NSKernAttributeName:@1.5f,};

글꼴 관련
    //     :
    [mString addAttribute:NSKernAttributeName value:@10 range:range];
    //    :
    [mString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:22] range:range];
    //      :
    [mString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    //       :
    [mString addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:range];
    //     NSStrokeWidthAttributeName                     NSForegroundColorAttributeName    
    [mString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:range];
    [mString addAttribute:NSStrokeWidthAttributeName value:@3 range:range];
    //   
    [mString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
    //   
    [mString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
    //    
    NSShadow *shadow = [[NSShadow alloc]init];
    shadow.shadowBlurRadius = 5;//     
    shadow.shadowColor = [UIColor blueColor];//      
    shadow.shadowOffset = CGSizeMake(1, 3);//        
    [mString addAttribute:NSShadowAttributeName value:shadow range:range];
    //      
    [mString addAttribute:NSVerticalGlyphFormAttributeName value:@(0) range:range];
    //    
    [mString addAttribute:NSObliquenessAttributeName value:@(1) range:range];
    //   
    [mString addAttribute:NSExpansionAttributeName value:@(1) range:range];

좋은 웹페이지 즐겨찾기