Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS6のNSAttributedString

Non Umemoto
February 23, 2013

 iOS6のNSAttributedString

NSAttributedStringで簡単にテキストをカスタマイズして、UITextViewにぶち込んだりできるよ。

Non Umemoto

February 23, 2013
Tweet

More Decks by Non Umemoto

Other Decks in Technology

Transcript

  1. UILabel *label = [[UILabel alloc] init]; ~~ লུ ~~ label.text

    = @"Listen to the web"; 13೥2݄24೔೔༵೔
  2. UILabel *label = [[UILabel alloc] init]; ~~ some codes for

    label ~~ NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; NSInteger stringLength = [attString length]; [attString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(0, stringLength)]; label.attributedText = attString; 13೥2݄24೔೔༵೔
  3. NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; UIColor

    *_red = [UIColor redColor]; [attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, 6)]; label.attributedText = attString; 13೥2݄24೔೔༵೔
  4. NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; [attString

    addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(10, 7)]; label.attributedText = attString; 13೥2݄24೔೔༵೔
  5. UIKitͰ࢖͑·͢ • UITextView • UITextField • UILabel • UIButton •

    UITableView • UIPickerVIew ྫ͑͹... 13೥2݄24೔೔༵೔
  6. AttributesͰ͍͡ΕΔࣄ • ϑΥϯτͷछྨ • ςΩετͷ৭ • ύϥάϥϑͷελΠϧ (ߴ͞ઃఆʹόά͋Δ) • ςΩετഎܠͷ৭

    • จࣈִؒͷௐ੔ͱ͔ • Լઢɺத๮ઢ͚ͭͨΓ • Ө͚ͭͨΓ ͦͷଞʹ΋͍Ζ͍Ζ (ৄ͘͠͸υΩϡϝϯτͰ) 13೥2݄24೔೔༵೔