iOS系统自带控件 UIBarButtonSystemItem 的样式解析

本文介绍了iOS系统自带控件UIBarButtonSystemItem中的UIBarButtonSystemItemFlexibleSpace和UIBarButtonSystemItemFixedSpace,它们分别用于调整工具条中按钮的间距和固定位置。通过在按钮之间插入这些对象,可以实现等间距分布或定制控件的位置。文中提供了示例代码和实际效果展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIBarButtonSystemItem的样式解析
样式图片
UIBarButtonSystemItemDone
UIBarButtonSystemItemCancel
UIBarButtonSystemItemEdit
UIBarButtonSystemItemSave
UIBarButtonSystemItemAdd
UIBarButtonSystemItemFlexibleSpace无样式
UIBarButtonSystemItemFixedSpace无样式
UIBarButtonSystemItemCompose
UIBarButtonSystemItemReply
UIBarButtonSystemItemAction
UIBarButtonSystemItemOrganize
UIBarButtonSystemItemBookmarks
UIBarButtonSystemItemSearch
UIBarButtonSystemItemRefresh
UIBarButtonSystemItemStop
UIBarButtonSystemItemCamera
UIBarButtonSystemItemTrash
UIBarButtonSystemItemPlay
UIBarButtonSystemItemPause
UIBarButtonSystemItemRewind
UIBarButtonSystemItemFastForward
UIBarButtonSystemItemUndo
UIBarButtonSystemItemRedo
UIBarButtonSystemItemPageCurl


可能有同学注意到  UIBarButtonSystemItemFlexibleSpace 和 UIBarButtonSystemItemFixedSpace 两个是无样式的.

那他们是做什么用的呢?

他们不是按钮,而是调整按钮间距用的对象.


让4个按钮等间距地分布在工具条中,在使用UIViewController的setToolbarItems:方法 追加按钮时,如下述代码一样在4个按钮之间追加IBarButtonSys
temItemFlexibleSpace对象即可。

例如下图:


首先创建方法

-  (UIBarButtonItem*)barButtonSystemItem :(UIBarButtonSystemItem) systemItem {
    
    UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:nil action:nil];
    
    return button;
    
}

调用

    [self setToolbarItems:[NSArray arrayWithObjects:[self barButtonSystemItem:UIBarButtonSystemItemAction],
                           [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],
                           [self barButtonSystemItem:UIBarButtonSystemItemBookmarks],
                           [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],
                           [self barButtonSystemItem:UIBarButtonSystemItemCancel],
                           [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],
                           [self barButtonSystemItem:UIBarButtonSystemItemEdit],nil]];


在调用的过程中,使用  UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目的

实现效果:



相应的 UIBarButtonSystemItemFixedSpace则是使特定位置控件替代.






更多精彩文章,尽在我的公众号.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值