7

Here's my code:

UILabel *myLabel;
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 480)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines
myLabel.text = @"Please select at least one image category!";
myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size: 24.0];
myLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
myLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:myLabel];
[myLabel release];

I was wondering if it is possible to center the wrapped text as it is alined to the left side: alt text

Undo
  • 25,519
  • 37
  • 106
  • 129
Linuxmint
  • 4,716
  • 11
  • 44
  • 64

3 Answers3

26
myLabel.textAlignment=UITextAlignmentCenter;
Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
arunkumar.p
  • 1,775
  • 4
  • 18
  • 31
13

UITextAlignmentCenter was the correct method to center the text, but is now depreciated. - see this question and answer.

Use NSTextAlignmentCenter instead:

label.textAlignment = NSTextAlignmentCenter;

This was mentioned in a comment, just making it clear for rookies like myself.

Community
  • 1
  • 1
Joshua Dance
  • 8,847
  • 4
  • 67
  • 72
1

Use this:

myLabel.textAlignment = NSTextAlignmentCenter;

UITextAlignmentCenter is deprecated from iOS 6!

Prashant Kumar
  • 20,069
  • 14
  • 47
  • 63
FredVDH
  • 301
  • 1
  • 3
  • 4