[obcj] UIButton, underline

iPhone 2013. 9. 14. 16:35



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

    NSDictionary *attributes = @{                                 NSUnderlineStyleAttributeName@(NSUnderlineStyleSingle)};

    [attrStr addAttributes:attributes

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

    

    [self.btn setAttributedTitle:attrStr forState:UIControlStateNormal];


    

Posted by tenn
,


NSString *str = @"part1 part2 part3";

NSRange range = [str rangeOfSring:@"part2"];


Posted by tenn
,





    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:@""]];





Posted by tenn
,