hgpl
hgpl

Reputation: 869

Different font in one Label

I am using one label in navigation bar item.In that label two types of font are there.Suppose label.text = @"Topics";

In this "T" is having font Georgia and "opics" is having the font Arial.

How I will do this?

I tried with self.navigationItem.titleView but it is taking all font same type, I tried with two string with different font and append those two.But that also didn't work. Please help.

Upvotes: 1

Views: 1745

Answers (2)

Krishnabhadra
Krishnabhadra

Reputation: 34275

There is no straightforward way..

1) Use two UILabels, each with a different font.. Move the second one over the first based on where the first one's text ends. You can use sizeWithFont:forWidth:lineBreakMode: to size of one text

2)Other option, you subclass UILabel, draw text in drawRect:, Use any logic to differentiate between 2 strings in different fonts

3) There is a third possibility..But since I never tried it, I can't give much information..May be this question might be of help..

EDIT : In iOS 6 UILabel, UITextView and other similar classes support NSAttributedString which can be used to have different font types/styles in single label text. This answer clearly explains it. So no need to add it here.

Upvotes: 1

WrightsCS
WrightsCS

Reputation: 50707

Your not going to be able to use 2 different fonts on 1 label.

I would suggest using 2 labels aligned properly to get the "1 label" look, then you can set the font for each label.

Upvotes: 0

Related Questions