Different font sizes on one label?

Is it possible to have a different font or weight in the same UILabel? I can do this in the storyboard as an Attributed label, but I need to do this programmatically.

cell.lblOne.text = [NSString stringWithFormat: @"FontSize15:: %@, FontSize20:: %@",monkey, goat]; 

Edit: I saw something about NSAttributedString, but I can't get it to work.

+7
source share
1 answer

Take a look at my answer here:

Alternative to UITextView

  • create NSMutableAttributedString
  • give it some attributes (apply to character ranges)
  • set attribute property labelText

.

  NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString: @"monkey goat"]; [attString addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(0,6)]; [attString addAttribute: NSFontAttributeName value: [UIFont fontWithName:@"Helvetica" size:15] range: NSMakeRange(0,6)]; [attString addAttribute: NSFontAttributeName value: [UIFont fontWithName:@"Didot" size:24] range: NSMakeRange(7,4)]; self.label.attributedText = attString; 
+17
source

All Articles