#import "ViewController.h"
#import "HHMenuCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"金刚区滑条";
[self.view addSubview:self.tableView];
}
#pragma mark - lazy
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 0.0;
_tableView.sectionHeaderHeight = 0.0;
_tableView.sectionFooterHeight = 0.0;
_tableView.estimatedSectionHeaderHeight = 0.0;
_tableView.estimatedSectionFooterHeight = 0.0;
[_tableView registerClass:[HHMenuCell class] forCellReuseIdentifier:NSStringFromClass([HHMenuCell class])];
}
return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HHMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([HHMenuCell class])];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 165;
}
@end
///===================================================================
滑动条原理
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIView *baseView;
@property (nonatomic,strong) UIView *topView;
@property (nonatomic,assign) CGFloat x;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"金刚区滑条";
[self.view addSubview:self.baseView];
[self.baseView addSubview:self.topView];
}
- (UIView *)baseView {
if (!_baseView) {
_baseView = [[UIView alloc] init];
_baseView.frame = CGRectMake(100, 200, [UIScreen mainScreen].bounds.size.width - 200, 6);
_baseView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
_baseView.layer.cornerRadius = 3;
_baseView.layer.masksToBounds = YES;
}
return _baseView;
}
- (UIView *)topView {
if (!_topView) {
_topView = [[UIView alloc] init];
_topView.frame = CGRectMake(0, 0, 80, 6);
_topView.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.8];
_topView.layer.cornerRadius = 3;
_topView.layer.masksToBounds = YES;
}
return _topView;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
self.x += 1;
CGRect frame = CGRectMake(self.x, 0, 80, 6);
self.topView.frame = frame;
}
@end