Center Align text in UITableViewCell problem

后端 未结 9 1275
梦如初夏
梦如初夏 2020-12-05 04:02

I\'m kinda new to Objective-C and iPhone development and I\'ve come across a problem when trying to center the text in a table cell. I\'ve searched google but the solutions

9条回答
  •  清歌不尽
    2020-12-05 04:19

    Here is what works for me...

    NSString *text = @"some text";
    CGSize size = [text sizeWithAttributes:@{NSFontAttributeName:SOME_UIFONT}];
    
    [cell setIndentationLevel:1];
    [cell setIndentationWidth:(tableView.frame.size.width - size.width)/2.0f];
    
    cell.textLabel.font = SOME_UIFONT;
    [cell.textLabel setText:text];
    

提交回复
热议问题