Center Align text in UITableViewCell problem

后端 未结 9 1279
梦如初夏
梦如初夏 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:36

    In same situation I created custom UITableViewCell with a custom label:

    MCCenterTextCell.h file:

    #import 
    
    @interface MCCenterTextCell : UITableViewCell
    
    @property (nonatomic, strong) UILabel *mainLabel;
    
    @end
    

    MCCenterTextCell.m file:

     #import "MCCenterTextCell.h"
    
    
    @interface MCCenterTextCell()
    
    
    @end
    
    
    @implementation MCCenterTextCell
    
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
    
            self.accessoryType = UITableViewCellAccessoryNone;
            self.selectionStyle = UITableViewCellSelectionStyleGray;
            _mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 320, 30)];
            _mainLabel.font = BOLD_FONT(13);
            _mainLabel.textAlignment = NSTextAlignmentCenter;
            [self.contentView addSubview:_mainLabel];
    
        }
        return self;
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    
    @end
    

提交回复
热议问题