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
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