写一个简单的自定义UITabelView

首先写一个自定义的BaseTableViewCell

import “BaseTableViewCell.h”

@implementation BaseTableViewCell

  • (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    }

  • (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellSize:(CGSize)cellsize
    {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    }
    return self;
    }

  • (void)drawRect:(CGRect)rect
    {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);

    //上分割线,
    CGContextSetStrokeColorWithColor(context, ([UIColor clearColor]).CGColor);
    CGContextStrokeRect(context, CGRectMake(0, -1, rect.size.width, 1));

    //下分割线
    CGContextSetStrokeColorWithColor(context, ([UIColor colorWithWhite:237.0 / 255.0 alpha:1.0]).CGColor);
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
    }

  • (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    }

@end

然后创建一个要用到的UITabelView

import “ScenicSpotOrderDetailsViewController.h”

@interface ScenicSpotOrderDetailsViewController ()

pragma mark - table view dataSource

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
    }

//返回多少行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}

  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath {
    NSInteger row = indexPath.row;

    switch (row) {
    case 0:
    return 251;
    break;
    default:
    break;
    }

    return 108;
    }

  • (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{
    }

-(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = indexPath.row;

static NSString *cellIndentifier = @"BaseTableViewCell";
CGSize cellSize = [tableView rectForRowAtIndexPath:indexPath].size;

BaseTableViewCell *cell  = [tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
    cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier cellSize:cellSize];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

switch (row) {
    case 0:{

        break;
    }
    default:
        break;
}

return cell;

}

@end

自己用xib搭建View,再把View add到cell中,简单明了的tabelView就出来了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值