您好,欢迎来到尔游网。
搜索
您的当前位置:首页当UITableViewCell被选中时,上面的自定义view消失的问题

当UITableViewCell被选中时,上面的自定义view消失的问题

来源:尔游网

view又会重新显示出来,这是什么原因呢?


view并没有消失,只是变透明了而已。

下面是从苹果官方文档拷贝的:
UITableViewCell changes the background color of all sub views when cell is selected or highlighted.
意思就是说当UITableViewCell被选中或者高亮的时候,它的所有子view的颜色都会改变。

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

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

// CustomTableViewCell.h

@interface CustomTableViewCell : UITableViewCell

@property (weak, nonatomic) UIView *redline;

@end



// CustomTableViewCell.m

@implementation CustomTableViewCell

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    
    _redView.backgroundColor = [UIColor redColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    _redView.backgroundColor = [UIColor redColor];
}

@end


意即当选中或高亮时都显示它原本的颜色,这样就不会"消失"啦!

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务