关于(UITableViewcell)contentView高度的问题

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
- (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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值