UI_UIToolbar

//

//  ViewController.m

//  UIToolbar

//

//  Created by HarrySun on 16/7/13.

//  Copyright © 2016 Mobby. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@property (nonatomic,strong)UIToolbar *toolBar;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.view.backgroundColor = [UIColorgrayColor];

    

    self.toolBar = [[UIToolbaralloc]initWithFrame:CGRectMake(0,self.view.frame.size.height - 40, self.view.bounds.size.width,40)];

    [self.viewaddSubview:self.toolBar];

    

    self.toolBar.barStyle = UIBarStyleBlackOpaque//工具栏的风格,有黑白两种

    self.toolBar.translucent = YES; // 设置工具栏是否透明

    self.toolBar.tintColor = [UIColorredColor];    //设置item风格颜色

//    self.toolBar.barTintColor = [UIColor yellowColor];  // 设置工具栏背景色,会覆盖工具栏风格

    

    

    [self.toolBarsetBackgroundImage:[UIImageimageNamed:@"工具栏背景"]forToolbarPosition:(UIBarPositionAny)barMetrics:(UIBarMetricsCompactPrompt)]; //设置工具栏背景

    [self.toolBarsetShadowImage:[UIImageimageNamed:@"阴影图案"]forToolbarPosition:(UIBarPositionBottom)]; //设置阴影图案

    

    

    

    UIBarButtonItem *item1 = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"zuoshitu"]style:(UIBarButtonItemStylePlain)target:selfaction:@selector(change1)];

    

    UIBarButtonItem *item2 = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"zuoshitu"]style:(UIBarButtonItemStylePlain)target:selfaction:@selector(change2)];

    

    UIBarButtonItem *item3 = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"zuoshitu"]style:(UIBarButtonItemStylePlain)target:selfaction:@selector(change3)];

    

    UIBarButtonItem *flexible = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];   // 创建barbuttonitem,样式为flexible,这种是放在两个barbuttonitem之间的,调整两个item之间的距离.UIBarButtonSystemItemFlexibleSpace表示系统给一个合适的宽度,UIBarButtonSystemItemFixedSpace表示是用户可以自定义个宽度

    

    

    NSArray *array = [NSArrayarrayWithObjects:flexible,item1,flexible,item2,flexible,item3,flexible,nil];

    

    [self.toolBarsetItems:arrayanimated:YES];//item添加到toolbar

    [self.toolBarsizeToFit];

    

    

    

    

}


- (void)change1{

    

    NSLog(@"点击了第一个按钮");

}


- (void)change2{

    

    NSLog(@"点击了第二个按钮");

}


- (void)change3{

    

    NSLog(@"点击了第三个按钮");

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值