12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- //
- // DRTopLevelView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRTopLevelView.h"
- #import "DRTopRuleView.h"
- @interface DRTopLevelView ()<UIScrollViewDelegate>
- @property (nonatomic, strong) UIScrollView *scollView;
- @end
- @implementation DRTopLevelView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
-
- [self addSubview:self.scollView];
- [self.scollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(0);
- }];
-
- CGFloat width = SCREEN_WIDTH-40;
- for (int i = 1; i <=3; i++) {
- DRTopRuleView *rule = [[DRTopRuleView alloc] initWithFrame:CGRectMake(0, 10, 0, 10)];
- [rule requestDataWithIndex:i];
- [self.scollView addSubview:rule];
- [rule mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(width*(i-1));
- make.top.mas_equalTo(0);
- make.width.mas_equalTo(width);
- make.height.mas_equalTo(self.scollView.mas_height);
- }];
- }
-
-
- }
- - (void)setScrollViewContentHeight:(CGFloat)height {
- CGFloat width = SCREEN_WIDTH-40;
- self.scollView.contentSize = CGSizeMake(width*3, height);
- }
- - (void)setScollViewIndex:(NSInteger)index {
- [self.scollView setContentOffset:CGPointMake((SCREEN_WIDTH-40)*(index-1), 0) animated:NO];
-
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- CGFloat offx = scrollView.contentOffset.x;
- NSInteger index = offx/scrollView.width;
- if (self.delegate && [self.delegate respondsToSelector:@selector(TopLevelViewChangePage:)]) {
- [self.delegate TopLevelViewChangePage:index];
- }
- }
- - (UIScrollView *)scollView {
- if (!_scollView) {
- _scollView = [[UIScrollView alloc] init];
- _scollView.pagingEnabled = YES;
- _scollView.showsVerticalScrollIndicator = NO;
- _scollView.showsHorizontalScrollIndicator = NO;
- _scollView.bounces = NO;
- _scollView.delegate = self;
- }
- return _scollView;
- }
- @end
|