图片如下:

UIBarButtonSystemItem样式UIBarButtonSystemItemAdd

UIBarButtonSystemItem样式UIBarButtonSystemItemCompose

UIBarButtonSystemItem样式UIBarButtonSystemItemReply

UIBarButtonSystemItem样式UIBarButtonSystemItemAction

UIBarButtonSystemItem样式UIBarButtonSystemItemOrganize

UIBarButtonSystemItem样式UIBarButtonSystemItemBookmarks

UIBarButtonSystemItem样式UIBarButtonSystemItemSearch

UIBarButtonSystemItem样式UIBarButtonSystemItemRefresh

UIBarButtonSystemItem样式UIBarButtonSystemItemStop

UIBarButtonSystemItem样式UIBarButtonSystemItemCamera

UIBarButtonSystemItem样式UIBarButtonSystemItemTrash

UIBarButtonSystemItem样式UIBarButtonSystemItemPlay

UIBarButtonSystemItem样式UIBarButtonSystemItemPause

UIBarButtonSystemItem样式UIBarButtonSystemItemRewind

UIBarButtonSystemItem样式UIBarButtonSystemItemFastForward

UIBarButtonSystemItem样式UIBarButtonSystemItemUndo

UIBarButtonSystemItem样式UIBarButtonSystemItemRedo

 

#program mark  UIBarButtonSystemItemFlexibleSpace

罗列的所有的系统按钮,实际UIKit中还提供了两个没有出现在表中的常量。分别是UIBarButtonSystemItemFlexibleSpace 以及  UIBarButtonSystemItem FixedSpace 。这些也是UIBarButtonSystemItem类型常量,但是不是按钮,而是调整按钮间距用的对象。例如,如果没有进行任何处理,依次追加4个按钮后,按钮将显示在工具条左侧,如图3-24所示。

UIBarButtonSystemItem样式
 

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

[self setToolbarItems:[NSArray arrayWithObjects:

                     [self barButtonSystemItem:UIBarButtonSystemItemAction]          
     // 追加间距对象UIBarButtonSystemItemFlexibleSpace                       
                                                                             
                     [self barButtonSystemItem:UIBarButtonSystemItemFlexi

 bleSpace]                                                                   

                     [self barButtonSystemItem:UIBarButtonSystemItemBookmarks]

     // 追加间距对象UIBarButtonSystemItemFlexibleSpace

                     [self barButtonSystemItem:UIBarButtonSystemItemFlexi

 bleSpace]

                     [self barButtonSystemItem:UIBarButtonSystemItemReply]

     // 追加间距对象UIBarButtonSystemItemFlexibleSpace

                     [self barButtonSystemItem:UIBarButtonSystemItemFlexi

 bleSpace]

                     [self barButtonSystemItem:UIBarButtonSystemItemCompose]

                     nil]];

这里为了让代码看起来更整齐,创建了一个新方法barButtonSystemItem:,只需要向此方法中传入系统按钮的常量就可以创建对应的系统按钮了,相关代码如下。

     -  (UIBarButtonItem*)barButtonSystemItem :(UIBarButtonSystemItem)

 systemItem {

        UIBarButtonItem* button =

          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem

                                       target:nil

                                       action:nil] autorelease];

        return button;

      }

执行后,将显示如图3-25所示的效果。

UIBarButtonSystemItem样式

如上述实例所示, UIBarButtonSystemItemFlexibleSpace 能自动调节按钮间的间距。

另外,不仅可以调整按钮间的间距,将其配置到左端(传递给setToolbarItems:方法的数组的第一个元素)时,可创建靠右的工具条按钮(见图3-26)。同时配置到左右端(数组的第一项及最后一项)时,将创建居中的工具条按钮(见图3-27)。
 

UIBarButtonSystemItem样式

如果不想自动调整按钮间的间距,而是指定固定间距值时,使用UIBarButton SystemItemFixedSpace 。通过指定UIBarButtonSystemItemFixedSpace创建UIBarButtonItem实例,然后通过width属性指定宽度。以下是实例代码。

                // 指定  UIBarButtonSystemItemFixedSpace 创建UIBarButtonItem实例

                UIBarButtonItem*fixedSpace =  [self barButtonSystemItem:UIBarButton

           SystemItemFixedSpace];

                // 将宽度固定为35个像素

                fixedSpace.width = 35;

                // 以35个像素取代其中一个按钮

                 [self setToolbarItems:[NSArray arrayWithObjects:

                 [self barButtonSystemItem:UIBarButtonSystemItemAction],

                 [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],

                 [self barButtonSystemItem:UIBarButtonSystemItemBookmarks],

                 [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],

                    fixedSpace,

                   [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],

                   [self barButtonSystemItem:UIBarButtonSystemItemCompose],

                   nil]];

代码执行后,显示如图3-28所示的效果。UIBarButtonSystemItemFixedSpace主要用于有特定按钮显示/隐藏间切换需要的场合,通过它当按钮隐藏时不至于破坏工具条的外观。

UIBarButtonSystemItem样式
 

 <部分内容来源于网络>

 

相关文章:

  • 2021-12-20
  • 2022-01-02
  • 2021-12-10
  • 2021-09-17
  • 2021-11-12
  • 2021-06-09
  • 2021-11-29
  • 2021-12-20
猜你喜欢
  • 2021-09-29
  • 2021-11-21
  • 2021-11-02
  • 2021-10-14
  • 2021-12-31
  • 2021-09-15
  • 2021-12-20
  • 2021-06-19
相关资源
相似解决方案