Custom TableBar for iOS

Source: Internet
Author: User

// TablebarView. h
// ChageView
//
// Created by LEE on 13-10-6.
// Copyright (c) 2013 LEE. All rights reserved.
//


# Import <UIKit/UIKit. h>

-(Void) tablebarViewDelegate :( NSInteger) tag;
@ End

@ Interface TablebarView: UIView

@ Property (nonatomic, strong) UIButton * button2;
@ Property (nonatomic, strong) UIButton * button3;
@ Property (nonatomic, strong) UIButton * button4;
@ Property (nonatomic, strong) UIButton * button5;
@ Property (nonatomic, strong) UIButton * button6;

// TablebarView. m
// ChageView
//
// Created by LEE on 13-10-6.
// Copyright (c) 2013 LEE. All rights reserved.
//

# Import "TablebarView. h"

# Define kScreenHeight (kIsIphone5? 548: 460)
# Define kScreenWidth [UIScreen mainScreen]. bounds. size. width
# Define STEP 5
# Define BarSection ([UIScreen mainScreen]. bounds. size. width)/STEP
@ Implementation TablebarView
@ Synthesize delegate;
-(Id) initWithFrame :( CGRect) frame
{
Self = [super initWithFrame: frame];
If (self)
{

Self. backgroundColor = [UIColor greenColor];
NSLog (@ "% f", [UIScreen mainScreen]. bounds. size. width );
// The buttons are arranged from left to right.
_ Button1 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button1.frame = CGRectMake (0, 0, BarSection, 44 );
[_ Button1 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button1.tag= 2013;
[Self addSubview: _ button1];

_ Button2 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button2.frame = CGRectMake (BarSection, 0, BarSection, 44 );
[_ Button2 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button2.tag = 2014;
[Self addSubview: _ button2];

_ Button3 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button3.frame = CGRectMake (BarSection * 2, 0, BarSection, 44 );
[_ Button3 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button3.tag = 2015;
[Self addSubview: _ button3];

_ Button4 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button4.frame = CGRectMake (BarSection * 3, 0, BarSection, 44 );
[_ Button4 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button4.tags = 2016;
[Self addSubview: _ button4];

_ Button5 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button5.frame = CGRectMake (BarSection * 4, 0, BarSection, 44 );
[_ Button5 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button5.tag= 2017;
[Self addSubview: _ button5];

_ Button6 = [UIButton buttonWithType: UIButtonTypeCustom];
_ Button6.frame = CGRectMake (BarSection * 5, 0, BarSection, 44 );
[_ Button6 addTarget: self action: @ selector (tableBarDelegate :) forControlEvents: UIControlEventTouchUpInside];
_ Button6.tags = 2018;
[Self addSubview: _ button6];

}
Return self;
}

-(Void) tableBarDelegate :( UIButton *) buttonTag
{
[Delegate tablebarViewDelegate: buttonTag. tag];
}

@ End

// ChangeViewViewController. h
// ChageView
//
// Created by LEE on 13-10-3.
// Copyright (c) 2013 LEE. All rights reserved.
//

# Import <UIKit/UIKit. h>

@ Interface changeViewViewController: UIViewController
@ Property (nonatomic, strong) UIButton * btn1;
@ Property (nonatomic, strong) UIButton * btn2;
@ Property (nonatomic, strong) UIScrollView * scrowView;
@ End

// ChangeViewViewController. m
// ChageView
//
// Created by LEE on 13-10-3.
// Copyright (c) 2013 LEE. All rights reserved.
//

# Import "changeViewViewController. h"
# Import "redController. h"
# Import "blueController. h"
# Import "TablebarView. h"

@ Interface changeViewViewController () <UIScrollViewDelegate, TablebarViewDelegate>

@ End

@ Implementation changeViewViewController

-(Void) viewDidLoad
{
[Super viewDidLoad];

_ ScrowView = [[UIScrollView alloc] init];
_ ScrowView. frame = CGRectMake (0, 0,320, self. view. frame. size. height );
_ ScrowView. contentSize = CGSizeMake (10,100 0 );
_ ScrowView. delegate = self;
_ ScrowView. backgroundColor = [UIColor redColor];

// Add the scroll View to the current view
[Self. view addSubview: _ scrowView];
// Add tableBar to the scroll View
TablebarView * tableBar = [[TablebarView alloc] init];
TableBar. frame = CGRectMake (0,100, self. view. frame. size. width, 44 );
TableBar. button1.backgroundColor = [UIColor blackColor];
TableBar. button2.backgroundColor = [UIColor whiteColor];
TableBar. button3.backgroundColor = [UIColor blueColor];
TableBar. button4.backgroundColor = [UIColor greenColor];
TableBar. button5.backgroundColor = [UIColor brownColor];
TableBar. button6.backgroundColor = [UIColor purpleColor];
TableBar. delegate = self;
[_ ScrowView addSubview: tableBar];

}

-(Void) tablebarViewDelegate :( NSInteger) tag
{
Switch (tag ){
Case 2013:
{
NSLog (@ "% d", tag );
}
Break;
Case 2014:
{
NSLog (@ "% d", tag );

}
Break;
Case 2015:
{
NSLog (@ "% d", tag );
}
Break;
Case 2016:
{
NSLog (@ "% d", tag );
}
Break;
Case 2017:
{
NSLog (@ "% d", tag );
}
Break;
Case 2018:
{
NSLog (@ "% d", tag );
}
Break;

Default:
Break;
}

}

-(Void) didReceiveMemoryWarning
{
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@ End


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.