自分でtableviewクラスを持つプロジェクトを1つ作成します。テーブルビューの任意のセルに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;
}