2016-01-07 UIToolbar

//

//  GZToolbarViewController.m

//  toolbar

//

//  Created by Apple on 16/1/7.

//  Copyright © 2016 ShangYu. All rights reserved.

//

 

#import "GZToolbarViewController.h"

 

@interface GZToolbarViewController ()

 

@end

#define SCREENW [UIScreen mainScreen].bounds.size.width

#define SCREENH [UIScreen mainScreen].bounds.size.height

@implementation GZToolbarViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    self.view.backgroundColor=[UIColor whiteColor];

//

    self.title=@"toolBar";

//    UIToolbar *toolBar=[[ UIToolbar alloc ] initWithFrame : CGRectMake ( 0 , self.view.frame.size.height - 44 , self.view.frame.size.width/2 , 44 )];

    UIToolbar *toolBar=[[ UIToolbar alloc ] initWithFrame : CGRectMake ( 0, self.view.frame.size.height - 44 , 30 , 44 )];

 

//    toolBar. barStyle = UIBarButtonItemStylePlain ;

//    toolBar.barStyle=UIBarStyleBlackOpaque;

    toolBar.backgroundColor=[UIColor clearColor];

    [ self . view addSubview :toolBar];

 

    UIBarButtonItem *sapce=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];

    sapce.width=-15;

    

    

    UIButton  *yellowBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREENW/2, 44)];

    yellowBtn.backgroundColor=[UIColor blueColor];

    [yellowBtn addTarget:self action:@selector(yellowCkick) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *addItem=[[UIBarButtonItem alloc]initWithCustomView:yellowBtn];

    

    

    UIBarButtonItem *sapce1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];

    sapce1.width=-10;

    

    UIButton  *redBtn=[[UIButton alloc]initWithFrame:CGRectMake(SCREENW/2, 0, SCREENW/2, 44)];

    redBtn.backgroundColor=[UIColor redColor];

    [redBtn addTarget:self action:@selector(redClick) forControlEvents:UIControlEventTouchUpInside];

 

    UIBarButtonItem *jianItem=[[UIBarButtonItem alloc]initWithCustomView:redBtn];

    

     NSArray *items=[ NSArray arrayWithObjects :sapce,addItem,sapce1,jianItem,

                     nil ];

    toolBar.items=items;

 

    [toolBar sizeToFit];

    

    

    

    

    

//

//    UIButton  *yellowBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2, 44)];

//    yellowBtn.backgroundColor=[UIColor yellowColor];

// 

//    UIBarButtonItem *addItem=[[UIBarButtonItem alloc]initWithCustomView:yellowBtn];

//    

//    

////    UIBarButtonItem *Item=[[ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemFlexibleSpace target : self action : nil ];

////    Item.width=0;

//    

//    

//    UIButton  *redBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2, 0, self.view.frame.size.width/2, 44)];

//    redBtn.backgroundColor=[UIColor redColor];

//    

//    UIBarButtonItem *editItem=[[ UIBarButtonItem alloc ]initWithCustomView:redBtn];

//    

//    NSArray *items=[ NSArray arrayWithObjects :addItem,editItem, nil ];

//    

//    [ self setToolbarItems :items];  //UIToolBar添加UIBarButtonItem

//    [ self . navigationController setToolbarHidden : NO animated : NO ];

    

 

 

}

 

-(void)yellowCkick{

    NSLog(@"yellow");

}

-(void)redClick{

 

    NSLog(@"red");

}

 

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

posted @ 2016-01-07 17:43  zhen_zhen  阅读(116)  评论(0编辑  收藏  举报