Rishi
Rishi

Reputation: 2017

Not able to change font size in UILabel

I have a label named label. Now, I am initializing the font of the label like this:

label.font = UIFont(name: fontFamily!, size: 32.0)

Now, when I am printing the label.font, this is the output:

<UICTFont: 0x79694a70> font-family: ".HelveticaNeueInterface-Regular"; font-weight: normal; font-style: normal; font-size: 17.00pt

The font-size is always 17.00pt whatever size I pass to UIFont. What can be the error? Or am I missing something?

Edit:

After checking everything, it seemed that the name of font that I was passing was wrong because of which it was creating a default UIFont() instance. If someone has this problem, may check if he/she is passing the correct name or not.

Thanks

Upvotes: 1

Views: 555

Answers (2)

Deepak
Deepak

Reputation: 1441

Try this

yourLable.text = "Your text will be here"

yourLable.textAlignment = NSTextAlignment.Right
yourLable.textAlignment = .Right

yourLable.textColor = UIColor.redColor()
yourLable.shadowColor = UIColor.blackColor()
yourLable.font = UIFont(name: "HelveticaNeue", size: CGFloat(22))

Upvotes: 0

Woodstock
Woodstock

Reputation: 22926

Try it like this:

let font = UIFont(name: "Helvetica", size: 32.0)
label.font = font

I think that implicitly unwrapped optional is causing issues. - the default system font is size 17, Helvetica Neue.

Upvotes: 1

Related Questions