0

I would like to create a one lined UILabel with a simple formatting that would look like this: enter image description here

Never mind the underlining - it's the Photoshop thing.

I basically have 2 parts of the text, the left one with one font family, size and color, and another one with another. Adding 2 labels one after another would make things extremely problematic and complicated. Any ideas how would you combine the thing into one simple UILabel? thanks in advance!

EDIT: I don't use Storyboards or XIB's and I'm building for iOS 5.1 and up

Robert Harvey
  • 173,679
  • 45
  • 326
  • 490
Sergey Grischyov
  • 11,895
  • 19
  • 78
  • 118

4 Answers4

4

If you want to run iOS 5.0 and up, you can use the wonderful TTTAttributedLabel by mattt.

Anupdas
  • 10,126
  • 2
  • 34
  • 60
3

I've used both of the following in apps that run in iOS 5+.

XJones
  • 21,918
  • 10
  • 64
  • 81
2

You can use two UILabels aligned with one another using autolayout, or you can use the attributedText property available in iOS6

Dan F
  • 17,304
  • 5
  • 70
  • 110
1

You can use attributedText property to handle this.

NSMutableAttributedString* string = [NSMutableAttributedString attributedStringWithString:@"OneThing (AnotherThing)"];

//this sets the font for the whole string

[string setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetice-Neue"]}];

//write another font here for "OneThing"

[string setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetice-Neue"]} range:NSMakeRange(0, 7)];

myLabel.attributedText = string;

Khawar Ali
  • 3,402
  • 4
  • 26
  • 52