自定义UITableView
1.controller
SpecialSaleView *view = [[SpecialSaleView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-64-44-49)];
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
_specialView = view;
2.view
#import <UIKit/UIKit.h>
@interface SpecialSaleView : UIView
@end
#import "SpecialSaleView.h"
#import "HWDConstant.h"
@interface SpecialSaleView ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak) UITableView * tableView;
@end
@implementation SpecialSaleView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self createTableView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
// CGRect frame = CGRectMake(0, 0, self.width, self.height);
// if (!CGRectEqualToRect(frame, _tableView.frame)) {
// _tableView.frame = CGRectMake(0, 0, self.width, self.height);
// }
}
- (void)createTableView{
UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
tableView.delegate = self;
tableView.dataSource=self;
[self addSubview:tableView];
_tableView = tableView;
//headerView
UIView*headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 380)];
headerView.backgroundColor=[UIColor purpleColor];
_tableView.tableHeaderView=headerView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * reuseID = @"cell";
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (cell== nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseID];
}
cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
cell.textLabel.text = @"100000000";
return cell;
}
@end