UIToolbar 工具条

UIToolbar 继承UIView 多个UIBarButtonItem的容器

barStyle:

UIBarStyleDefault.

UIBarStyleBlack 黑背景,白字风格

UIbarStyleBlackOpaque(黑色不透明背景,白字风格)

UIBarStyleBlackTranslucent(黑色透明背景,白色风格)

Fixed Space Bar Button Item 工具条上固定宽度的空白间隔 对象是UIBarButtomItem 的实例

BarButtomIterm 工具条上的按钮

Flexible Space Bar Buttom Item 工具条上可伸缩宽度的空白间隔  亦为实例 默认会“努力占据” 更多的宽度,因此,如果在最后一个按钮钱插入FLexibleSpaceBarButtonItem 即可把最后一个按钮“挤到”工具条的最右边

提示:

如果程序需要将工具条上的按钮放置在工具条中间,可以选择在该按钮的左右两边各放置一个FlexibleSpacebarButtonItem

UIToolBar几乎可以放置任何空间,只要将其包装为UIBarButtonItem即可

-initWithTitle:style:target:action: 初始化包装一个普通按钮的UIBarbuttonItem

-initWithImage:style:target:action: 初始化包装为UIImageView的UIBarbuttonItem

-initWithBarBUttonSystemItem:target:action 初始化包装系统按钮的...这个系统按钮的图标、风格都是固定的。该方法需要一个UIBarButtonSystemItem类型的枚举值

-initWithCustomView: 初始化包装任意UI控件的... 需要传入一个UIView参数

- (void)viewDidLoad {

[super viewDidLoad];

self.toolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 40, 540, 50)];

self.toolbar.barStyle=UIBarStyleBlack;

[self.view addSubview:self.toolbar];

UIBarButtonItem* bn1=[[UIBarButtonItem alloc]

initWithTitle:@"OK" style:UIBarButtonItemStylePlain target:self action:@selector(clicked:)];

//创建使用自定义图片的UIBarButtonItem

UIBarButtonItem* bn2=[[UIBarButtonItem alloc]

initWithImage:[UIImage imageNamed:@"heart.gif"] style:UIBarButtonItemStyleBordered target:self action:@selector(clicked:)];

//创建使用系统图标的UIBBI

UIBarButtonItem* bn3=[[UIBarButtonItem alloc]

initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clicked:)];

//可伸缩

UIBarButtonItem* flexItem=[[UIBarButtonItem alloc]

initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

//

self.prog=[[UIProgressView alloc]

initWithProgressViewStyle:UIProgressViewStyleBar];

self.prog.frame=CGRectMake(0, 0, 80, 20);

//设置改进度条的初始进度为0

self.prog.progress=0;

//创建使用UIView的UIBBI

UIBarButtonItem* bn4=[[UIBarButtonItem alloc]

initWithCustomView:self.prog];

self.toolbar.items=[NSArray arrayWithObjects:bn1,bn2,bn3,bn4, nil];

_timer=[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES];

[_timer fire];

// Do any additional setup after loading the view, typically from a nib.

}

-(void)clicked:(id)sender{

UIAlertController* alertController=[UIAlertController alertControllerWithTitle:@"您的选择" message:[NSString stringWithFormat:@"%@",sender] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* defaultAction=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];//一个UIAlertAction是一个按钮 和其事件

[alertController addAction:defaultAction];

[self presentViewController:alertController animated:YES completion:nil];

}

-(void)changeProgress

{

//如果进度满,则停止计时器

if (self.prog.progress>=1.0) {

[self.prog setProgress:0.0 animated:YES];

}

else

{

[self.prog setProgress:self.prog.progress+0.1

animated:YES];

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 840评论 0 0
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 1,741评论 0 3
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 1,591评论 2 4
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,093评论 3 38
  • 总觉得自己患有严重的心疾,与我走的愈近,愈觉得我这病太可怕。 愚人节,心堵。越发觉得自己在处理对待好多事情上面,太...
    我想养只狗叫卡尔彬阅读 480评论 0 0