UI_UIToolbar

来源:互联网 发布:霓虹灯led动画软件 编辑:程序博客网 时间:2024/05/16 06:13

//

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


0 0
原创粉丝点击