pmk*_*pmk 5 iphone objective-c uitableview uiimageview ios
所以我面临着在我的内部设置custum selectedBackgroundView的问题UITableViewCell.
我的单元格contentView基本上是一个UIView(frame = 0,0,80,70),黑色背景和UIImageView子视图.
imageView的 contentMode = UIViewContentModeScaleAspectFit;
这看起来像这样:

现在我像这样设置selectedBackgroundView:
//set the custom selected color
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = MY_TINT_COLOR;
CGColorRef darkColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha: 0.25].CGColor;
CGColorRef lightColor = [self.view.backgroundColor colorWithAlphaComponent:0.0].CGColor;
//setting some gradients here
//should not be relevant for the question
[cell setSelectedBackgroundView:bgColorView];
Run Code Online (Sandbox Code Playgroud)
这导致如下所示:

我现在的问题是selectedBackgroundView隐藏黑色部分的原因是contentView什么?
我已经尝试bgColorView用一个帧开始初始化我x = 80,但这并没有改变任何东西.
此外,我曾试图显式设置backgroundColor的imageView黑色,同样的结果.
什么可能导致这种行为?
Ani*_*ese 23
下图给出了单元结构的概念.选定的背景视图将隐藏内容视图
因此,您可以尝试将单元格的背景颜色设置为黑色.您的自定义单元格看起来像这样
self.backgroundColor = [UIColor blackColor]; // Gives black background for you
// Set selected background view
UIView *backgroundView = [[UIView alloc]initWithFrame:self.bounds];
backgroundView.layer.borderColor = [[UIColor colorWithRed:0.529 green:0.808 blue:0.922 alpha:1]CGColor];
backgroundView.layer.borderWidth = 10.0f;
self.selectedBackgroundView = backgroundView;
[backgroundView release];
// Set the content view
CGRect frame = CGRectMake(self.bounds.origin.x+5, self.bounds.origin.y+5, self.bounds.size.width-10, self.bounds.size.height-10);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageView = imageView;
[imageView release];
self.imageView.contentMode = UIViewContentModeScaleAspectFill ;
self.imageView.clipsToBounds = YES;
[self.contentView addSubview:self.imageView];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12836 次 |
| 最近记录: |