9

iOS 7 が組み込みの accessoriesTypes とは異なる方法でカスタム accessoriesViews をレイアウトすることに気付いた人はいますか?

このような:

ここに画像の説明を入力

一番上のものは次を使用して行われます:

cell.accessoryView = cell.accessoryButton;

(accessoryButton はカスタマイズされた UIButton です) 一方、2 つ目は次を使用して行われます。

cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

同じコード、同じアプリ、同じ Xcode を、代わりに iOS 6 で実行:

ここに画像の説明を入力

これは SDK のバグですか? または、コードを介して制御できるものはありますか?

4

2 に答える 2

23

サブクラス化するUITableViewCell場合は、調整できますlayoutSubviews

- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect accessoryViewFrame = self.accessoryView.frame;
    accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame);
    self.accessoryView.frame = accessoryViewFrame;
}
于 2013-09-26T06:33:09.970 に答える
0

accessoriesView の代わりにサブビューを追加

UIButton *indicatorBtn = [UIButton  buttonWithType:UIButtonTypeCustom];
indicatorBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50);
[indicatorBtn setBackgroundImage:[UIImage imageNamed:@"right_indicator.png"] 
                     forState:UIControlStateNormal];
indicatorBtn.backgroundColor = [UIColor clearColor];
//indicatorBtn.alpha = 0.5;
indicatorBtn.tag = indexPath.row;
[indicatorBtnaddTarget:self action:@selector(method:) 
    forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:indicatorBtn];
于 2014-09-18T05:05:10.357 に答える