单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
//  SegmentedPage.m
//  BaseProject
//
//  Created by WindShan on 2016/12/9.
//  Copyright © 2016年 WindShan. All rights reserved.
//
 
#import "SegmentedPage.h"
#import "HMSegmentedControl.h"
#import "NetworkTestPage.h"
#import "view1.h"
#import "view2.h"
#import "view3.h"
#import "view4.h"
 
@interface SegmentedPage ()<UIScrollViewDelegate>
 
@property (nonatomic, strong) UIScrollView        *scrollView;
//@property (nonatomic, strong) HMSegmentedControl  *segmentedControl;
 
/*! views */
@property (nonatomic, strong) view1 *views1;
@property (nonatomic, strong) view2 *views2;
@property (nonatomic, strong) view3 *views3;
@property (nonatomic, strong) view4 *views4;
 
@end
 
@implementation SegmentedPage
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*! 设置CGRectZero从导航栏下开始计算 */
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    [self buildSegment];
 
    // Do any additional setup after loading the view.
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
#pragma mark - ***** 配置segment
- (void)buildSegment
{
    //self.segmentedControl.hidden = NO;
    self.scrollView.hidden       = NO;
    self.views1.hidden           = NO;
    self.views2.hidden           = NO;
    self.views3.hidden           = NO;
    self.views4.hidden           = NO;
}
 
static inline UIColor *ba_RGBAColor(float r,float g,float b, float a) { return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a];}
 
/*! 浅灰色 0.667 white */
#define BA_LightGray_Color      ba_RGBAColor(255, 255, 255, 0.667)
/*! 白色 1.0 white */
#define BA_White_Color          ba_RGBAColor(255, 255, 255, 1)
/*! 绿色 0.0, 1.0, 0.0 RGB */
#define BA_Green_Color          ba_RGBAColor(0, 255, 0, 1)
 
 
//- (HMSegmentedControl *)segmentedControl
//{
//    if (!_segmentedControl)
//    {
//        _segmentedControl                             = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
//        //        _segmentedControl                           = [[HMSegmentedControl alloc] init];
//        
//        /*! 设置标题 */
//        _segmentedControl.sectionTitles               = @[@"最新",@"排行榜",@"手机",@"新闻",@"游戏",@"数码",@"段子",@"科技"];
//        /*! 自适应宽度,随着屏幕滑动自动滚动 */
//        _segmentedControl.autoresizingMask            = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
//        /*! 默认选中第0个view */
//        _segmentedControl.selectedSegmentIndex        = 0;
//        /*! 标题背景颜色 */
//        _segmentedControl.backgroundColor             = [UIColor clearColor];
//        /*! 标题默认字体颜色 */
//        _segmentedControl.titleTextAttributes         = @{NSForegroundColorAttributeName : BA_LightGray_Color, NSFontAttributeName: BA_FontSize(16)};
//        /*! 标题选中字体颜色 */
//        _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : BA_White_Color, NSFontAttributeName: BA_FontSize(18)};
//        /*! 标题选中的下划线的颜色 */
//        _segmentedControl.selectionIndicatorColor     = BA_Green_Color;
//        /*! 标题选中的下划线的高度 */
//        _segmentedControl.selectionIndicatorHeight    = 2.0f;
//        /*! 标题选中的样式:本样式为下划线 */
//        _segmentedControl.selectionStyle              = HMSegmentedControlSelectionStyleFullWidthStripe;
//        /*! 标题选中的下划线的方向:本样式为向下 */
//        _segmentedControl.selectionIndicatorLocation  = HMSegmentedControlSelectionIndicatorLocationDown;
//        /*! 标题的中间的隔线:默认为:NO */
//        _segmentedControl.verticalDividerEnabled      = YES;
//        /*! 标题的中间的隔线颜色 */
//        _segmentedControl.verticalDividerColor        = BA_LightGray_Color;
//        /*! 标题的中间的隔线宽度 */
//        _segmentedControl.verticalDividerWidth        = 1.0f;
//        
//        //        [self.view addSubview:_segmentedControl];
//        
//        /*! 标题点击事件 */
//        BA_WEAKSELF;
//        [_segmentedControl setIndexChangeBlock:^(NSInteger index) {
//            [weakSelf.scrollView scrollRectToVisible:CGRectMake(SCREEN_WIDTH * index, 0, SCREEN_WIDTH, weakSelf.scrollView.frame.size.height) animated:YES];
//        }];
//        self.navigationItem.titleView = _segmentedControl;
//    }
//    return _segmentedControl;
//}
 
- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        /*! 这里的frame按实际情况更改! */
        self.scrollView                                = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BA_TabbarHeight - BA_StatusBarAndNavigationBarHeight)];
        self.scrollView.backgroundColor                = [UIColor whiteColor];
        self.scrollView.pagingEnabled                  = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.bounces                        = NO;
        self.scrollView.contentSize                    = CGSizeMake(SCREEN_WIDTH * 8, self.scrollView.frame.size.height);
        self.scrollView.delegate                       = self;
        self.scrollView.backgroundColor                = BA_Green_Color;
        
        [self.scrollView scrollRectToVisible:CGRectMake(0, 0, SCREEN_WIDTH, self.scrollView.frame.size.height) animated:NO];
        [self.view addSubview:self.scrollView];
        
    }
    return _scrollView;
}
 
#pragma mark - ***** UIScrollViewDelegate
 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat pageWidth = scrollView.frame.size.width;
    NSInteger page = scrollView.contentOffset.x / pageWidth;
    
    //[_segmentedControl setSelectedSegmentIndex:page animated:YES];
}
 
- (view1 *)views1
{
    if (!_views1)
    {
        _views1 = [[view1 alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.scrollView.frame.size.height) withSelectRowBlock:^(UITableView *tableView, NSIndexPath *indexPath, NSArray *dataArray) {
            
        }];
        [self.scrollView addSubview:_views1];
    }
    return _views1;
}
 
- (view2 *)views2
{
    if (!_views2)
    {
        _views2 = [[view2 alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, self.scrollView.frame.size.height) withSelectRowBlock:^(UITableView *tableView, NSIndexPath *indexPath, NSArray *dataArray) {
            
        }];
        [self.scrollView addSubview:_views2];
    }
    return _views2;
}
 
- (view3 *)views3
{
    if (!_views3)
    {
        _views3 = [[view3 alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 2, 0, SCREEN_WIDTH, self.scrollView.frame.size.height) withSelectRowBlock:^(UITableView *tableView, NSIndexPath *indexPath, NSArray *dataArray) {
            
        }];
        [self.scrollView addSubview:_views3];
    }
    return _views3;
}
 
- (view4 *)views4
{
    if (!_views4)
    {
        _views4 = [[view4 alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 3, 0, SCREEN_WIDTH, self.scrollView.frame.size.height) withSelectRowBlock:^(UITableView *tableView, NSIndexPath *indexPath, NSArray *dataArray) {
            
        }];
        [self.scrollView addSubview:_views4];
    }
    return _views4;
}
 
/*
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 
@end