我要创建一个在 self.tableview 类中的项目。我在 tableview 的任何单元格中有 3 件事。(1 个按钮(左侧)和 2 个标签,如底部图像)
我希望标题单元格正确对齐,但我做不到。
这是我的代码。我的错误在哪里:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
_backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"copymove-cell-bg"]];
[_backgroundImageView setContentMode:UIViewContentModeTopRight];
[self setBackgroundView:_backgroundImageView];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
_iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_iconButton setFrame:CGRectMake(0, 10, 47, 50)];
[_iconButton setAdjustsImageWhenHighlighted:NO];
[_iconButton addTarget:self action:@selector(iconButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_iconButton setImage:[UIImage imageNamed:@"item-icon-folder"] forState:UIControlStateNormal];
[_iconButton setImage:[UIImage imageNamed:@"item-icon-folder-selected"] forState:UIControlStateSelected];
[_iconButton setImage:[UIImage imageNamed:@"item-icon-folder-selected"] forState:UIControlStateHighlighted];
[self.contentView addSubview:_iconButton];
_titleTextField = [[UILabel alloc] initWithFrame:CGRectMake(69, 29, _titleTextField.frame.size.width, _titleTextField.frame.size.height)];
[_titleTextField setFont:KOFONT_FILES_TITLE];
[_titleTextField setTextColor:KOCOLOR_FILES_TITLE];
[_titleTextField.layer setShadowColor:KOCOLOR_FILES_TITLE_SHADOW.CGColor];
[_titleTextField setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin];
[_titleTextField.layer setShadowOffset:CGSizeMake(0, 1)];
[_titleTextField.layer setShadowOpacity:1.0f];
[_titleTextField.layer setShadowRadius:0.0f];
[_titleTextField setTextAlignment:UITextAlignmentRight];
[_titleTextField setLineBreakMode:UILineBreakModeMiddleTruncation];
[self.contentView addSubview:_titleTextField];
[self.layer setMasksToBounds:YES];
_countLabel = [[UILabel alloc] initWithFrame:CGRectMake(273, 29, 47, 28)];
[_countLabel setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin];
[_countLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"item-counter"]]];
[_countLabel setTextAlignment:UITextAlignmentCenter];
[_countLabel setLineBreakMode:UILineBreakModeMiddleTruncation];
[_countLabel setFont:KOFONT_FILES_COUNTER];
[_countLabel setTextColor:KOCOLOR_FILES_COUNTER];
[_countLabel setShadowColor:KOCOLOR_FILES_COUNTER_SHADOW];
[_countLabel setShadowOffset:CGSizeMake(0, 1)];
[self setAccessoryView:_countLabel];
[self.accessoryView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin];
}
return self;
}