iOS開發基礎知識

2021-07-30 20:34:30 字數 1294 閱讀 7983

在ios中,你能看得見摸得著的東西基本上都是uiview,比如乙個按鈕、乙個文字標籤、乙個文字輸入框、乙個圖示等等,這些都是uiview。

其實uiview之所以能顯示在螢幕上,完全是因為它內部的乙個圖層:

在建立uiview物件時,uiview內部會自動建立乙個圖層(即calayer物件),通過uiview的layer屬性可以訪問這個層。

@property(nonatomic,readonly,retain) calayer *layer;
當uiview需要顯示到螢幕上時,會呼叫drawrect:方法進行繪圖,並且會將所有內容繪製在自己的圖層上,繪圖完畢後,系統會將圖層拷貝到螢幕上,於是就完成了uiview的顯示。

換句話說,uiview本身不具備顯示的功能,是它內部的層才有顯示功能。

因此,通過調節calayer物件,可以很方便的調整uiview的一些外觀屬性。

寬度和高度:

@property cgrect bounds;
位置(預設指中點,具體由anchorpoint決定):

@property cgpoint position;
錨點(x,y的範圍都是0-1),決定了position的含義:

@property cgpoint anchorpoint;
背景顏色(cgcolorref型別):

@property cgcolorref backgroundcolor;
形變屬性:

@property catransform3d transform;
position和anchorpoint的作用

@property cgpoint position;:
用來設定calayer在父層中的位置

以父層的左上角為原點(0, 0)

@property cgpoint anchorpoint;:
稱為「定位點」、「錨點」,

決定著calayer身上的哪個點會在position屬性所指的位置。

以自己的左上角為原點(0, 0),

它的x、y取值範圍都是0~1,預設值為中心點(0.5, 0.5)

anchorpoint和position的關係舉例:

假如錨點anchorpoint為預設值即中點(0.5,0.5),而該層的position設定為(0,0)即為父層的左上點,那麼該層在父層中只會看到四分之一的部分。

iOS開發UI Button基礎知識

二 建立button按鈕 建立乙個btn物件,根據型別來建立btn 圓角型別btn uibuttontyperoundedrect 通過類方法來建立buttonwithtype 類名 方法名 uibutton btn uibutton buttonwithtype uibuttontyperound...

IOS開發基礎知識 碎片32

1 動畫屬性uiviewanimationoptions說明 a 常規動畫屬性設定 可以同時選擇多個進行設定 uiviewanimationoptionlayoutsubviews 動畫過程中保證子檢視跟隨運動。uiviewanimationoptionallowuserinteraction 動畫...

iOS開發基礎知識 碎片24

ios開發基礎知識 碎片24 1 相容字型大小6plue跟它以下的區別 define font compatible screen offset fontsize uifont systemfontofsize fontsize uiscreen mainscreen scale 2 在iphone...