TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2017 |
Maintained by wuxu.
pod 'SListView','~>1.0.0'
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = @[randomColor,randomColor,randomColor,randomColor,randomColor];
[self.view addSubview:self.listView];
}
- (IBAction)reload:(id)sender {
self.dataSource = @[randomColor,randomColor,randomColor,randomColor,randomColor,randomColor,randomColor,randomColor];
[self.listView reloadData];
}
#pragma mark - SListViewDataSource
- (NSInteger)numberOfColumnsInListView:(SListView *)listView {
return self.dataSource.count;
}
- (CGFloat)listView:(SListView *)listView widthForColumnAtIndex:(NSInteger)index {
return index % 2? 70:90;
}
- (SListViewCell *)listView:(SListView *)listView viewForColumnAtIndex:(NSInteger)index {
static NSString *identifier = @"ListViewCellIdentifier";
SListViewCell *cell = [listView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[SListViewCell alloc] initWithIdentifier:identifier];
}
[self configureCell:cell atIndex:index];
return cell;
}
- (void)configureCell:(SListViewCell *)cell atIndex:(NSInteger )index {
cell.backgroundColor = _dataSource[index];
}
#pragma mark - SListViewDelegate
- (void)listView:(SListView *)listView didSelectColumnAtIndex:(NSInteger)index {
NSLog(@"listView didSelectColumnAtIndex >> %ld",index);
}
- (void)listView:(SListView *)listView didScrollToColumn:(SRange)range {
NSLog(@"didScrollToColumn start:%ld end:%ld",range.start,range.end);
}
#pragma mark - lazy init
- (SListView *)listView {
if (!_listView) {
_listView = [[SListView alloc] initWithFrame:CGRectMake(0, 150, CGRectGetWidth(self.view.frame), 200)];
_listView.dataSource = self;
_listView.delegate = self;
}
return _listView;
}