您的位置:首页 > 移动开发 > IOS开发

iOS开发笔记--Cell选中时候上面View看不见

2016-05-12 18:38 676 查看
今天开发中遇见一个问题,就是cell被选中时候,cell上面的view全部都看不见了。其实View并没消失,只是透明了。

下面是从苹果官方文档拷贝的:

UITableViewCell changes the background color of all sub views when cell is selected or highlighted.

意思就是说当UITableViewCell被选中或者高亮的时候,它的所有子view的颜色都会改变。

如果你不喜欢让它变透明,你可以在你的自定义UITableViewCell里重写这两个方法:

假设那个view叫testview,它的颜色为红色。

// CustomTableViewCell.h

@interface CustomTableViewCell : UITableViewCell

@property (strong, nonatomic) UIView *testview;

@end

// CustomTableViewCell.h

@implementation CustomTableViewCell

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];

self.testview.backgroundColor = [UIColor redColor];
}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

self.testview.backgroundColor = [UIColor redColor];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios ios开发 苹果