我创建了一个自己拥有tableview类的项目。 我有3件事在tableview的任何单元格。 (1个按钮(左边)和2拉布勒状底部图像)如何在单元格tableview上对齐UILabel?
我想标题单元格是右对齐,但我不能这样做。
这是我的代码。哪里是我的错误:
- (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;
}
U可以尝试有针对的TableView细胞笔尖好让你不必给代码框架和代码将是一个很多清洁剂。 –
尝试使用相同的标签宽度? – tom19830924
@ tom19830924我这样做,但不工作:( – david