UI 09 自定义cell

我们能够发现系统的cell有时候不能够满足我们的要求, 这时候我们就需要自定义属于我们的cell
新建一个继承于UITableViewCell 文件.
注意, cell的属性名字绝对不能够和系统的一样

#import <UIKit/UIKit.h>

@interface ThreeANDTwoTableViewCell : UITableViewCell
@property(nonatomic, retain)UIImageView *imageviewOne;
@property(nonatomic, retain)UIImageView *imageviewTwo;
@property(nonatomic, retain)UIImageView *imageviewThree;
@property(nonatomic, retain)UILabel *leftLabel;
@property(nonatomic, retain)UILabel *rightLabel;


@end

在.m中有两个方法, 一个是初始化, 一个是layOutViews

#import "ThreeANDTwoTableViewCell.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height
@implementation ThreeANDTwoTableViewCell
- (void)dealloc{
    [_imageviewOne release];
    [_imageviewThree release];
    [_imageviewTwo release];
    [_leftLabel release];
    [_rightLabel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatViews];
    }
    return self;
}
- (void)creatViews{
    // 再初始化中不设置fram
    self.imageviewOne = [[UIImageView alloc] init];
    self.imageviewOne.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.imageviewOne];
    [_imageviewOne release];

    self.imageviewTwo = [[UIImageView alloc] init];
    self.imageviewTwo.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.imageviewTwo];
    [_imageviewTwo release];

    self.imageviewThree = [[UIImageView alloc] init];
    self.imageviewThree.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.imageviewThree];
    [_imageviewThree release];

    self.leftLabel = [[UILabel alloc] init];
    self.leftLabel.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.leftLabel];
    self.leftLabel.textAlignment = NSTextAlignmentCenter;
    [_leftLabel release];

    self.rightLabel = [[UILabel alloc] init];
    self.rightLabel.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.rightLabel];
    self.rightLabel.textAlignment = NSTextAlignmentCenter;
    [_rightLabel release];


}
- (void)layoutSubviews{
    // 一定不要遗忘super!
    [super layoutSubviews];
    self.imageviewOne.frame = CGRectMake(0, 0,WIDTH/3, HEIGHT/3*2);
    self.imageviewTwo.frame = CGRectMake(WIDTH/3, 0, WIDTH/3, HEIGHT/3*2);
    self.imageviewThree.frame = CGRectMake(WIDTH/3*2, 0, WIDTH/3, HEIGHT/3*2);
    self.leftLabel.frame = CGRectMake(0, HEIGHT/3*2, WIDTH/2, HEIGHT/3);
    self.rightLabel.frame = CGRectMake(WIDTH/2, HEIGHT/3*2, WIDTH/2, HEIGHT/3);

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值