Ios top tab

Source: Internet
Author: User

Ios top tab

Scrolview is mainly used

//

// HJPagerViewController. h

// MusicLove

//

// Created by niuxinghua on 15/1/29.

// Copyright (c) 2015 Hjojo. All rights reserved.

//


# Import

@ Interface HJPagerViewController: UIViewController

@ Property (nonatomic, strong) UIScrollView * scrolview;

@ Property (nonatomic, strong) UIButton * btn1;

@ Property (nonatomic, strong) UIButton * btn2;

@ Property (nonatomic, strong) UIButton * btn3;

@ Property (nonatomic, strong) UIImageView * imageLine;

@ Property (nonatomic, strong) UITableView * tableView;


@ End



/

//

// HJPagerViewController. m

// MusicLove

//

// Created by niuxinghua on 15/1/29.

// Copyright (c) 2015 Hjojo. All rights reserved.

//


# Import "HJPagerViewController. h"

# Import "MJRefresh. h"


NSString * const MJTableViewCellIdentifier = @ "Cell1 ";


/**

* Random data

*/

# Define MJRandomData [NSString stringWithFormat: @ "random data --- % d", arc4random_uniform (1000000)]



@ Interface HJPagerViewController ()

@ Property (strong, nonatomic) NSMutableArray * fakeData;

@ End


@ Implementation HJPagerViewController


-(Void) viewDidLoad {

[SuperviewDidLoad];

// Do any additional setup after loading the view.

Self. tabBarController. tabBar. hidden = YES;

Self. fakeData = [[NSMutableArrayalloc] init];

CGFloat mainWith = [UIScreenmainScreen]. bounds. size. width;

CGFloat mainHeight = [UIScreenmainScreen]. bounds. size. height;

_ Btn1 = [[UIButtonalloc] initWithFrame: CGRectMake (, mainWith/)];

_ Btn1.backgroundColor = [UIColorcolorWithRed: 242/255. 0 green: 87/255. 0 blue: 96/255. 0 alpha: 1.0f];

// [_ Btn1 setBackgroundColor: [UIColor blackColor];

[_ Btn1setTitle: @ "distance" forState: UIControlStateNormal];

_ Btn2 = [[UIButtonalloc] initWithFrame: CGRectMake (mainWith/3,66, mainWith/3,40)];

_ Btn2.backgroundColor = [UIColorcolorWithRed: 242/255. 0 green: 87/255. 0 blue: 96/255. 0 alpha: 1.0f];

[_ Btn2setTitle: @ "price" forState: UIControlStateNormal];

_ Btn3 = [[UIButtonalloc] initWithFrame: CGRectMake (mainWith/3*2, 66, mainWith/3, 40)];

_ Btn3.backgroundColor = [UIColorcolorWithRed: 242/255. 0 green: 87/255. 0 blue: 96/255. 0 alpha: 1.0f];

[_ Btn3setTitle: @ "" forState: UIControlStateNormal];

_ ImageLine = [[UIImageViewalloc] initWithFrame: CGRectMake (0,104, mainWith/)];

_ ImageLine. center = CGPointMake (mainWith/6,107.5 );

[_ ImageLinesetBackgroundColor: [UIColorgreenColor];

_ Scrolview = [[UIScrollViewalloc] initWithFrame: CGRectMake (0,111, mainWith, mainHeight-111)];

_ Scrolview. delegate = self;

_ Scrolview. pagingEnabled = YES;

_ Scrolview. showsHorizontalScrollIndicator = NO;

_ Scrolview. bounces = NO;

_ Scrolview. contentSize = CGSizeMake (mainWith * 3, mainHeight-111 );

Self. tableView = [[UITableViewalloc] initWithFrame: CGRectMake (0, mainWith, mainHeight-111)];

// 2. Integrated refresh control


[SelfsetupRefresh];


[Self. tableViewregisterClass: [UITableViewCellclass] forCellReuseIdentifier: MJTableViewCellIdentifier];

Self. tableView. delegate = self;

Self. tableView. dataSource = self;

UIImageView * image1 = [[UIImageViewalloc] initWithFrame: CGRectMake (, mainWith, mainHeight-111)];

UIImageView * image2 = [[UIImageViewalloc] initWithFrame: CGRectMake (mainWith, 0, mainWith, mainHeight-111)];

UIImageView * image3 = [[UIImageViewalloc] initWithFrame: CGRectMake (mainWith *, mainWith, mainHeight-111)];

Image1.backgroundColor = [UIColorredColor];

Image2.backgroundColor = [UIColorblackColor];

Image3.backgroundColor = [UIColorgreenColor];

[_ ScrolviewaddSubview: self. tableView];

[_ ScrolviewaddSubview: image2];

[_ ScrolviewaddSubview: image3];

[Self. viewaddSubview: _ btn1];

[Self. viewaddSubview: _ btn2];

[Self. viewaddSubview: _ btn3];

[Self. viewaddSubview: _ scrolview];

[Self. viewaddSubview: _ imageLine];

[_ Btn1setTag: 101];

[_ Btn2setTag: 102];

[_ Btn3setTag: 103];

[_ Btn1addTarget: selfaction: @ selector (btnClicked :) forControlEvents: UIControlEventTouchUpInside];

[_ Btn2addTarget: selfaction: @ selector (btnClicked :) forControlEvents: UIControlEventTouchUpInside];

[_ Btn3addTarget: selfaction: @ selector (btnClicked :) forControlEvents: UIControlEventTouchUpInside];

}

-(Void) btnClicked :( UIButton *) sender {

Int tag = [sendertag];

If (tag = 101 ){

[UIViewanimateWithDuration: 0.5 fanimations: ^ {

_ ImageLine. center = CGPointMake (self. view. bounds. size. width/6, _ imageLine. center. y );

_ Scrolview. contentOffset = CGPointMake (0, 0 );

}];


}

Elseif (tag = 102 ){

[UIViewanimateWithDuration: 0.5 fanimations: ^ {

_ ImageLine. center = CGPointMake (self. view. bounds. size. width/2, _ imageLine. center. y );

_ Scrolview. contentOffset = CGPointMake (self. view. bounds. size. width, 0 );

}];

}

Else {

[UIView animateWithDuration: 0.5f animations: ^ {

_ ImageLine. center = CGPointMake (self. view. bounds. size. width/6*5, _ imageLine. center. y );

_ Scrolview. contentOffset = CGPointMake (self. view. bounds. size. width * 2, 0 );

}];

}

}

-(Void) scrollViewDidScroll :( UIScrollView *) scrollView {

_ ImageLine. center = CGPointMake (scrollView. contentOffset. x/3 + self. view. bounds. size. width/6, _ imageLine. center. y );

}

/**

* Integrated refresh control

*/

-(Void) setupRefresh

{

// 1. pull-down refresh (the headerRereshing of self will be called upon refreshing)

// [Self. tableView addHeaderWithTarget: self action: @ selector (headerRereshing)];

// DateKey is used to store the refresh time, which ensures different refresh times on different interfaces.

[Self. tableView addHeaderWithTarget: self action: @ selector (headerRereshing) dateKey: @ "table"];

[Self. tableView headerBeginRefreshing];

// 2. Pull up and load more (the footerRereshing of self will be called when the refresh state is enabled)

[Self. tableView addFooterWithTarget: self action: @ selector (footerRereshing)];

// Set text (you can also leave it unspecified. The default text is modified in MJRefreshConst)

Self. tableView. headerPullToRefreshText = @ "the drop-down list can be refreshed ";

Self. tableView. headerReleaseToRefreshText = @ "Refresh immediately after releasing ";

Self. tableView. headerRefreshingText = @ "is refreshing... ";

Self. tableView. footerPullToRefreshText = @ "more data can be loaded by pulling ";

Self. tableView. footerReleaseToRefreshText = @ "Releasing and loading more data now ";

Self. tableView. footerRefreshingText = @ "loading... ";

}


# Pragma mark starts to refresh

-(Void) headerRereshing

{

// 1. Add false data

For (int I = 0; I <5; I ++ ){

[Self. fakeData insertObject: MJRandomData atIndex: 0];

}

// 2. Refresh the table UI after two seconds of simulation (in real development, you can remove this gcd code)

Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {

// Refresh the table

[Self. tableView reloadData];

// (Preferably called after refreshing the table) Call endRefreshing to end the refresh status

[Self. tableView headerEndRefreshing];

});

}


-(Void) footerRereshing

{

// 1. Add false data

For (int I = 0; I <5; I ++ ){

[Self. fakeData addObject: MJRandomData];

}

// 2. Refresh the table UI after two seconds of simulation (in real development, you can remove this gcd code)

Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {

// Refresh the table

[Self. tableView reloadData];

// (Preferably called after refreshing the table) Call endRefreshing to end the refresh status

[Self. tableView footerEndRefreshing];

});

}


# Pragma mark-Table view data source

//-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView

//{

// Return 5;

//}


-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section

{

Returnself. fakeData. count;

}


-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath

{

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: MJTableViewCellIdentifier forIndexPath: indexPath];

Cell. textLabel. text = self. fakeData [indexPath. row];

NSLog (@ "% @", self. fakeData [indexPath. row]);

Return cell;

}


-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath

{

}


-(Void) didReceiveMemoryWarning {

[Super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}


/*

# 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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.