Hacker News new | past | comments | ask | show | jobs | submit login

For bolding text, create an attributed string and draw it with CoreText. http://stackoverflow.com/questions/8322020/display-nsattribu...

If you only support iOS 6, you can use a UILabel and set the "attributedText" property.

I notice a lot of new iOS developers jump to open source libraries to abstract away important frameworks. It might save an hour, but I think it's counterproductive to not do things by hand the first time.




Adding a little more detail: To stylize your content, you create a 'mask' by specifying the character ranges that you want to change, and then applying attributes to the string

Snippet to take a gray-colored string "Hello World", and then make "World" show as a black color (from memory):

  NSString *theEntireLineOfText = @"Hello World";
  UIColor *boldColor = [UIColor blackColor];
  UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:12.0];
  UIColor *baseColor = [UIColor grayColor];
  NSDictionary *subAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
                              myFont, NSFontAttributeName, boldColor,NSForegroundColorAttributeName, nil];
   NSMutableAttributedString *mainText = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",theEntireLineOfText] attributes:@{NSFontAttributeName:myFont,NSForegroundColorAttributeName:baseColor}];
  // Make the word "World" black"
  NSRange range = NSMakeRange(0,[@"World" length]);
        [mainText setAttributes:subAttrs range:range];




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: