IOS--UIToolBar详细使用

// 这个其实很简单,主要就是向上面添加按钮,然后点击按钮的方法
// 效果图
IOS--UIToolBar详细使用


// 主要代码

//

//  RootViewController.m

//  UIToolBar

//


#import "RootViewController.h"


@interface RootViewController ()


@end


@implementation RootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // 设置title

        self.title = @"UIToolBar的使用";

        // 设置背景色

        self.view.backgroundColor = [UIColor blueColor];

        

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    // 添加一个UIToolBar

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

    toolBar.tintColor = [UIColor purpleColor]; // 设置颜色

    toolBar.barStyle = UIBarStyleBlackTranslucent; // 设置样式

    toolBar.translucent = YES; // 设置为半透明的,但样式必须设置为UIBarStyleBlackTranslucent

    toolBar.hidden = NO// 隐藏toolBar

    // [toolBar setBackgroundImage:[UIImage imageNamed:@"abc"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; //设置背景图片

    // [toolBar setShadowImage:[UIImage imageNamed:@"abc"] forToolbarPosition:UIToolbarPositionBottom];

    

    // 添加到view

    [self.view addSubview:toolBar];

    [toolBar release];

    

    

    

   

    // 自定义样式

    UIBarButtonItem *firstButton = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:selfaction:nil];

    firstButton.tintColor = [UIColor redColor];

    

    // 设置固定的空隙

    UIBarButtonItem *twoButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:selfaction:nil];

    twoButton.width = 30.0f;

    twoButton.tintColor = [UIColor greenColor];

    

    // 播放样式按钮

    UIBarButtonItem *threeButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:selfaction:nil];

    threeButton.tintColor = [UIColor whiteColor];

    

    // 几个空间之间的距离平均分配

    UIBarButtonItem *twoButton1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:selfaction:nil];

    twoButton1.tintColor = [UIColor greenColor];

    

    // 暂停样式按钮

    UIBarButtonItem *fourButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:selfaction:nil];

    fourButton.tintColor = [UIColor yellowColor];

    

    // 添加到UIToolBar上面,并释放内存

    [toolBar setItems:@[firstButton, twoButton, threeButton, twoButton1, fourButton] animated:YES];

    [firstButton release], firstButton = nil;

    [twoButton release], twoButton = nil;

    [threeButton release], threeButton = nil;

    [twoButton1 release], twoButton1 = nil;

    [fourButton release], fourButton = nil;

    

    

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值