关于(UITableViewcell)contentView高度的问题

来源:互联网 发布:淘宝发货没有无需物流 编辑:程序博客网 时间:2024/05/16 04:16

cell.contentView.frame.size.height//高度默认为44.0
如果想改变这个数值,让它返回我们设置的row的高度
在重写cell的时候,要在layoutSubviews中设置子控件的frame,如果在init中设置控件frame则无效,还是返回默认高度。

#import "PTRuleTableViewCell.h"@interface PTRuleTableViewCell ()@property (strong, nonatomic) UIView *bottomLine;@property (strong, nonatomic) UILabel *label1;@property (strong, nonatomic) UIView *line1;@end@implementation PTRuleTableViewCell- (void)awakeFromNib {    [super awakeFromNib];    // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    // Configure the view for the selected state}- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        _bottomLine = [[UIView alloc] init];        _bottomLine.backgroundColor =  RGBCOLOR(60, 170, 250);        [self addSubview:_bottomLine];        _line1 = [[UIView alloc] init];        _line1.backgroundColor = RGBCOLOR(60, 170, 250);        [self addSubview:_line1];       _label1 = [[UILabel alloc] init];        _label1.backgroundColor = [UIColor clearColor];        [self addSubview:_label1];    }    return self;}-(void)layoutSubviews{    [super layoutSubviews];    _bottomLine.frame = CGRectMake(15*UIRate, self.contentView.frame.size.height - 0.5, SCREEN_WIDTH - 30*UIRate, 0.5);    _line1.frame = CGRectMake(15*UIRate, 0, 0.5, self.contentView.frame.size.height);    _label1.frame = CGRectMake(15*UIRate, 0, 90*UIRate, self.contentView.frame.size.height);}
1 0
原创粉丝点击