《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRTopLevelView.m 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // DRTopLevelView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRTopLevelView.h"
  9. #import "DRTopRuleView.h"
  10. @interface DRTopLevelView ()<UIScrollViewDelegate>
  11. @property (nonatomic, strong) UIScrollView *scollView;
  12. @end
  13. @implementation DRTopLevelView
  14. - (instancetype)initWithFrame:(CGRect)frame
  15. {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. [self initUI];
  19. }
  20. return self;
  21. }
  22. - (void)initUI {
  23. [self addSubview:self.scollView];
  24. [self.scollView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.left.right.top.bottom.mas_equalTo(0);
  26. }];
  27. CGFloat width = SCREEN_WIDTH-40;
  28. for (int i = 1; i <=3; i++) {
  29. DRTopRuleView *rule = [[DRTopRuleView alloc] initWithFrame:CGRectMake(0, 10, 0, 10)];
  30. [rule requestDataWithIndex:i];
  31. [self.scollView addSubview:rule];
  32. [rule mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.mas_equalTo(width*(i-1));
  34. make.top.mas_equalTo(0);
  35. make.width.mas_equalTo(width);
  36. make.height.mas_equalTo(self.scollView.mas_height);
  37. }];
  38. }
  39. }
  40. - (void)setScrollViewContentHeight:(CGFloat)height {
  41. CGFloat width = SCREEN_WIDTH-40;
  42. self.scollView.contentSize = CGSizeMake(width*3, height);
  43. }
  44. - (void)setScollViewIndex:(NSInteger)index {
  45. [self.scollView setContentOffset:CGPointMake((SCREEN_WIDTH-40)*(index-1), 0) animated:NO];
  46. }
  47. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  48. CGFloat offx = scrollView.contentOffset.x;
  49. NSInteger index = offx/scrollView.width;
  50. if (self.delegate && [self.delegate respondsToSelector:@selector(TopLevelViewChangePage:)]) {
  51. [self.delegate TopLevelViewChangePage:index];
  52. }
  53. }
  54. - (UIScrollView *)scollView {
  55. if (!_scollView) {
  56. _scollView = [[UIScrollView alloc] init];
  57. _scollView.pagingEnabled = YES;
  58. _scollView.showsVerticalScrollIndicator = NO;
  59. _scollView.showsHorizontalScrollIndicator = NO;
  60. _scollView.bounces = NO;
  61. _scollView.delegate = self;
  62. }
  63. return _scollView;
  64. }
  65. @end