Image View
在iPhone上要呈現圖需透過Image View這個元件來呈現,接著以簡單的範例來呈現。
該範例以簡單的Button事件來改變Image View呈現的圖片。


**Step 1.**建立SingleView
專案,專案命名為Image View
。
**Step 2.**編輯MainStoryboard.storyboard。
加入Image View
、Round Rect Button
兩個元件,元件的大小調整、Title這就不多做描述。

**Step 3.**加入圖片檔。
加入兩張圖片到該專案下(此範例僅使用兩張圖片作為範例)。

**Step 4.**編輯ViewController.h。
imageView_
是要用來顯示圖片。currentImage
是用來判斷目前要顯示哪張圖片。switchImage
為Button事件,用來改變圖片。
1 | @interface ViewController : UIViewController |
**Step 5.**編輯ViewController.m
- 將
currentImage
設為0。 - 並指定
imageView
的image為哪一個圖片檔(imageNamed
)。
1 | @synthesize imageView; |
switchImage
首先判斷currentImage
是否為0(零),條件成立時,將會改變currentImage
,並且改變imageView
的image,當下次在執行switchImage
時,一樣會先判斷currentImage
的值,並改變imageView
的image。
1 | -(IBAction)switchImage:(id)sender |
**Step 6.**建立關連
