iOS基礎-系統內建按鈕樣式- UIBarButtonSystemItem

來源:互聯網
上載者:User

標籤:

 

系統按鈕

除了映像與文字按鈕,還有一個小型的系統按鈕庫,可以建立那些在許多應用程式中都可以見到的標準化的預定義按鈕。系統按鈕也是UIBarButtonItem對象,可以通過類的initWithBarButtonSystemItem方法來建立。如下例:

  1. UIBarButtonItem *myBookmarks = [ [ UIBarButtonItem alloc ]  
  2.         initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks  
  3.         target: self  
  4.         action: @selector(mySelector:)  
  5. ]; 

表3-2是目前支援的系統按鈕,可以在UIBarButtonItem.h標頭檔中找到。

表3-2

按鈕標識符

描    述

UIBarButtonSystemItemDone

藍色文字按鈕,標有“Done”

UIBarButtonSystemItemCancel

文字按鈕,標有“Cancel”

UIBarButtonSystemItemEdit

文字按鈕,標有“Edit”

UIBarButtonSystemItemSave

藍色文字按鈕,標有“Save”

UIBarButtonSystemItemAdd

映像按鈕,上面有一個Å符號

UIBarButtonSystemItemFlexibleSpace

空白,佔用空間大小可變

UIBarButtonSystemItemFixedSpace

空白預留位置

UIBarButtonSystemItemCompose

映像按鈕,上有一支筆和紙張

UIBarButtonSystemItemReply

映像按鈕,上有一個回複箭頭

UIBarButtonSystemItemAction

映像按鈕,上有一個動作箭頭

UIBarButtonSystemItemOrganize

映像按鈕,上有一個檔案夾以及向下箭頭

UIBarButtonSystemItemBookmarks

映像按鈕,上有書籤表徵圖

UIBarButtonSystemItemSearch

映像按鈕,上有spotlight表徵圖

UIBarButtonSystemItemRefresh

映像按鈕,上有一個環形的重新整理箭頭

UIBarButtonSystemItemStop

映像按鈕,上有一個停止記號X

UIBarButtonSystemItemCamera

映像按鈕,上有一個照相機

UIBarButtonSystemItemTrash

映像按鈕,上有一個垃圾桶

UIBarButtonSystemItemPlay

映像按鈕,上有一個播放表徵圖

UIBarButtonSystemItemPause

映像按鈕,上有一個暫停表徵圖

UIBarButtonSystemItemRewind

映像按鈕,上有一個倒帶表徵圖

UIBarButtonSystemItemFastForward

映像按鈕,上有一個快進表徵圖


自訂視圖按鈕

與導覽列類似,按鈕也可以按照自訂視圖類來繪製,這樣你就可以將任何一種其他類型的視圖對象作為按鈕來顯示:

  1. UIBarButtonItem *customButton = [ [ UIBarButtonItem alloc ]  
  2.     initWithCustomView: myView ]; 

建立工具列

將所有希望顯示出來的按鈕都添加到前面建立的buttons數組:

  1. [ buttons addObject: buttonImage ];  
  2. [ buttons addObject: buttonText ];  
  3. [ buttons addObject: myBookmarks ]; 

下一步,建立一個UIToolbar對象,並將你的按鈕數組賦予工具列作為項目列表:

  1. UIToolbar *toolbar = [ [ UIToolbar alloc ] init ];  
  2. [ toolbar setItems: buttons animated: YES ]; 

最後,將你的導覽列的標題視圖替換為新建立的工具列,就像替換成分段控制項一樣:

  1. self.navigationItem.titleView = toolbar; 

當導覽列顯示出來時,工具列就會出現在它的中央。

調整大小

工具列會對加入的按鈕套用預設大小。如果你希望調整工具列,讓它可以更乾淨利落地適應導覽列的大小,可以用sizeToFit方法:

  1. [ toolbar sizeToFit ]; 

工具列的風格

就像許多其他基於視圖的對象一樣,UIToolbar也包含有一個風格屬性,名為barStyle。這個屬性可以用來調整工具列的風格,令其與你為導覽列定義的風格相匹配:

  1. toolbar.barStyle = UIBarStyleDefault; 

可以將工具列的風格設定為三種標準風格主題之一,這些主題也為大多數其他類型的欄狀對象所使用,如表3-3所示。

表3-3

 

風    格

描    述

UIBarStyleDefault

預設風格;灰色背景、白色文字

UIBarStyleBlackOpaque

純黑色背景、白色文字

UIBarStyleBlackTranslucent

透明黑色背景、白色文字

iOS基礎-系統內建按鈕樣式- UIBarButtonSystemItem

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.