3

I have a cell with two labels. How can I programmatically center-align the top label and hide the second label?

royhowie
  • 11,075
  • 14
  • 50
  • 67
Linux world
  • 3,750
  • 11
  • 44
  • 59
  • possible duplicate of [UILabel Align Text to center](http://stackoverflow.com/questions/5722730/uilabel-align-text-to-center) – royhowie May 26 '15 at 04:33

3 Answers3

8

UITextAlignmentCenter is deprecated. You should use the following:

labelOne.textAlignment = NSTextAlignmentCenter;
royhowie
  • 11,075
  • 14
  • 50
  • 67
Alessandro Pirovano
  • 2,509
  • 28
  • 21
4

[labelOne setTextAlignment:UITextAlignmentCenter]; //to center text in the UILabel [labelTwo setHidden:YES] //there, but not visible.

RickiG
  • 11,380
  • 13
  • 81
  • 120
0

I think what you are trying to do is: Something like this..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    firstLabel.frame = cell.frame; // or reconfigure your frame or some reason(i dont know)
    firstLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.hidden = YES;
}

you want you text from the firstLabel to be at the center of the cell?

0yeoj
  • 4,500
  • 3
  • 23
  • 41