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
  • 178,213
  • 47
  • 333
  • 501
Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120

4 Answers4

4

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

Anupdas
  • 10,211
  • 2
  • 35
  • 60
3

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

XJones
  • 21,959
  • 10
  • 67
  • 82
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,654
  • 5
  • 72
  • 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,462
  • 4
  • 27
  • 55