1

enter image description here

I use four fonts in the picture.It seems that different font has different vertical alignment in UILabel.

But I want to center in vertical or align top the text with different fonts in UILabel.

The labels is in fixed size.And I should not to change it in my program.

Any one can help me?

xushunwang
  • 283
  • 1
  • 2
  • 10
  • Use textalignment property for UILabel to center align but to make the text top align you need to set edgeinset for UILabel. – Exploring Jun 07 '13 at 06:50
  • There is no vertical alignment support in UILabel. There are some workarounds - see http://stackoverflow.com/questions/1054558/vertically-align-text-within-a-uilabel. – maroux Jun 07 '13 at 09:45

3 Answers3

2

Make use of the following code for center alignment.

label.textAlignment = NSTextAlignmentCenter;

This link answers your question in detail.

Community
  • 1
  • 1
Vinayak Kini
  • 2,919
  • 21
  • 35
0

For text alignment you can set as:

label.textAlignment = NSTextAlignmentCenter;

For changing the font use this,

label.font = [UIFont fontWithName:YOUR_FONT size:SIZE];
manujmv
  • 6,450
  • 1
  • 22
  • 35
0

yourLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:18]; // to set font style

You can get a list of the available fonts here.

For setting italics and bold, you can go here.

yourLabel.textAlignment = NSTextAlignmentCenter; // to set alignment to center

There is no direct or already-defined method to align text vertically, but you can find a cross-solution here.

Hope I helped.

Community
  • 1
  • 1
Charles D'Monte
  • 370
  • 4
  • 16