我創建了一個自己擁有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