2

alphaの に変更する必要がありselectedBackgroundViewますUITableViewCell。だから私は次のことをします:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor redColor];
    bgView.alpha = 0.5;//This setting has no effect
    cell.selectedBackgroundView = bgView;
}

セルは赤色で選択されていますが、アルファ設定は bgView には影響しません。

4

2 に答える 2

3

これを試して:

[bgView setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.5]];

編集::
サブビューにアルファ値を提供する際に既知の問題があります。理解を深めるために、このスレッドを参照してください:サブビューの UIView アルファ動作を制御する iOS

于 2013-09-16T08:49:41.760 に答える
3
// set selection color

UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor = [UIColor colorWithRed:1 green:0.0 blue:0.0 alpha:0.5];
cell.selectedBackgroundView = myBackView;
[myBackView release];

このリンクがお役に立てば幸いです。

選択したセルの背景色を変更しますか?

UITableView セルが選択されました 色?

于 2013-09-16T09:07:57.547 に答える