//
|
// 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
|