iPhone

[objc] UIButton에 NSAttributedString 적용

tenn 2013. 9. 14. 16:28





    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"ボタン"];

    

    /* フォント */

    [attrStr addAttribute:NSFontAttributeName

                    value:[UIFont fontWithName:@"ChalkboardSE-Regular" size:30.f]

                    range:NSMakeRange(0, attrStr.length)];

    /* 文字色 */

    [attrStr addAttribute:NSForegroundColorAttributeName

                    value:[UIColor cyanColor]

                    range:NSMakeRange(0, attrStr.length)];


    

    // 中抜き文字の枠線の色、下線、カーニングを一度に指定

    NSDictionary *attributes = @{NSStrokeColorAttributeName: [UIColor magentaColor],

                                 NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),

                                 NSKernAttributeName: @1.5};

    

    NSString *tStr = @"ボタン";

    

    [attrStr addAttributes:attributes

                     range:[tStr rangeOfString:@""]];