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);
}
本文介绍了如何在UITableViewCell中自定义底部线、标签和线条的高度,并通过在layoutSubviews方法中设置子控件的frame来实现高度调整。示例代码展示了初始化方法和布局方法的实现,确保了高度设置的有效性。
4601

被折叠的 条评论
为什么被折叠?



