SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Class 01
iOS 應⽤用軟體設計
課程⼤大綱
•   介紹、開發需求、開始 iOS 程式

•   置放按鈕,彈出視窗顯⽰示⽂文字 (UIButton
    +UIAlertView)

    •   QV053:⽤用程式碼寫作

    •   QV054:⽤用 xib 畫⾯面連接

•   學習圖⽚片的顯⽰示

•   按鈕切換圖⽚片 (UIImageView)

    •   QV055:使⽤用 xib

    •   QV056:使⽤用程式碼編寫
課程⼤大綱
請認清楚這些名詞
        Apple            Macintosh               iPhone
                       Mac              iMac        iPad
                                       Mac Pro
  Leopard (10.5)                                   iPod Touch
Snow Leopard (10.6)          MacBook
   Lion (10.7)                   MBP MBA
Mountain Lion (10.8)


         Mac OS X                                iOS
開發需求
硬體需求


Mac電腦 (Intel CPU)
 Mac OSX (最新版本 10.8)
iPhone、iPad、iPod Touch (⾮非必須)
 iOS (最新版本 6.0)
Mac 電腦




         http://store.apple.com/tw
Mac OS X
⿊黑蘋果 (不建議)

 使⽤用⾮非 Apple 的硬體安裝 Mac OS X
 安裝困難
 不穩定
 昇級問題重重
 缺乏完整的⽤用⼾戶使⽤用經驗
虛擬機器 (不建議)

 在 PC 內使⽤用虛擬機器軟體 (VM) 模擬 Mac
 速度慢
 操作不⽅方便
 沒有完整的⽤用⼾戶使⽤用經驗
開發軟體 (唯⼀一選擇)

                                     • xcode
                                      • 開發編輯器
                                      • iOS SDK
                                      • iOS 模擬器
                                      Interface Builder   Instruments

https://developer.apple.com/xcode/
開發者帳號
 價格:
  US$ 99 / 年 (個⼈人帳號)
  US$ 399 /  年 (公司帳號)
 功能:
  線上資源查詢整合
  上傳⾄至實機測試
  App上架發佈
開始 iOS 程式
xcode

   下載、安裝
   執⾏行
   開新專案
   在模擬器中執⾏行
預設範本為
開新專案選擇 iOS   Single View Application
專案名稱

                 公司識別

                  檔名前置⽂文字 (空⽩白)

                 設定裝置
Storyboards
 (暫不使⽤用)

⾃自動記憶體管理 (使⽤用)
指定⼀一個儲存位置
執⾏行功能         屬性設定、連接設定




               主要開發編寫介⾯面
檔案區




        偵錯輸出               元件選擇
執⾏行程式
於模擬器中查看結果
歡迎進⼊入學習之路......
範例:

     置放按鈕,按下後
     彈出視窗顯⽰示⽂文字

	

 	

 	

 QV053:⽤用程式碼寫作
	

 	

 	

 QV054:⽤用 xib 畫⾯面連接
Project QV053


按鈕物件 UIButton
警告顯⽰示 UIAlertView
CGRectMake
畫⾯面位置定義
在主畫⾯面載⼊入後執⾏行                  ViewController.m (1/2)


- (void)viewDidLoad
{
    [super viewDidLoad];
! // Do any additional setup after loading the view, typically from a nib.

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    myButton.frame = CGRectMake(100, 350, 120, 45);
    [myButton setTitle:@"按我" forState:UIControlStateNormal];
    [myButton addTarget:self
                 action:@selector(onClick:)
       forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:myButton];
}                                             (1) 宣告⼀一個按鈕
                                              (2) 設定位置
                                              (3) 設定標題⽂文字
                                              (4) 指定按下後執⾏行的程式
                                              (5) 置於在畫⾯面上
ViewController.m (2/2)



- (void)onClick:(id)sender
{
    NSLog(@"You click the Button!");

    UIAlertView *alert = [[UIAlertView alloc]
                           initWithTitle:@"Hello World"
                                 message:@"你按了按鈕"
                                delegate:self
                       cancelButtonTitle:@"OK"
                       otherButtonTitles:nil];

    [alert show];
}
UIButton 的樣式



試驗⼀一下:按鈕的其他樣式

  UIButtonTypeRoundedRect (圓⾓角⽅方形按鈕)

  UIButtonTypeDetailDisclosure (細節顯⽰示)

  UIButtonTypeInfoLight (⽩白⾊色資訊 i)

  UIButtonTypeInfoDark (深⾊色資訊 i)

  UIButtonTypeContactAdd (加號按鈕)

  UIButtonTypeCustom (使⽤用者⾃自訂)
同樣範例

(改⽤用 xib 設計畫⾯面再連接)
Project QV054

同 Project QV053,但採⽤用
xib  的⽅方式設計畫⾯面
設定 xib 畫⾯面與類別的連接
按鈕物件 UIButton
警告顯⽰示 UIAlertView
步驟⼀一:在 .h 檔案進⾏行宣告                               ViewController.h




 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController
 {
     IBOutlet UIButton *myButton;
 }                                              宣告在此類別,
 - (IBAction)onClick:(id)sender;           會需要的資料或元件
 @end
步驟⼆二:在 .xib 檔案佈置      ViewController.xib




               (2) 設定必要屬性




         (1) 拖移進⼊入畫⾯面擺放
建⽴立『物件』的關連




                       按住 Ctrl 鍵
             再⽤用滑⿏鼠由 "File's Owner" 拉到 "按鈕"
建⽴立『事件』的關連




                       按住 Ctrl 鍵
             再⽤用滑⿏鼠由 "按鈕" 拉到 "File's Owner"
確定接⼝口是否正確建⽴立   由 xib 中檢查
步驟三:在 .m 檔案實作程式                                   ViewController.m



- (void)viewDidLoad
{
    [super viewDidLoad];
! // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)onClick:(id)sender
{
    UIAlertView *alert = [[UIAlertView alloc]
                           initWithTitle:@"Hello World"
                                 message:@"你按了按鈕"
                                delegate:self
                       cancelButtonTitle:@"OK"
                       otherButtonTitles:nil];

    [alert show];
}
學習圖⽚片的顯⽰示
圖形的使⽤用

• 圖檔以 .png 檔最佳 (.jpg 亦可)
• 事先處理好圖檔的⼤大⼩小尺⼨寸
• 圖檔必須先加⼊入⾄至專案內
• 搭配 UIImage 及 UIImageView 使⽤用
範例:按鈕切換圖⽚片

	

 	

 	

 QV055:使⽤用 xib
	

 	

 	

 QV056:使⽤用程式碼編寫
Project QV055


採⽤用 xib  的⽅方式設計畫⾯面
圖⽚片物件 UIImageView
0
    準備好圖⽚片,將圖⽚片移⼊入專案內
0
0   可以另建 Group 分類整理檔案
0

    Group 為專案內的整理



          和實際存放的資料夾無關
1
                                  ViewController.h


    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController
    {
        IBOutlet UIImageView *myImageView01;
        IBOutlet UIImageView *myImageView02;
    }

    - (IBAction)btn1Click:(id)sender;
    - (IBAction)btn2Click:(id)sender;

    @end
2   ViewController.xib (1/4)
2   ViewController.xib (2/4)
2   ViewController.xib (3/4)
2   ViewController.xib (4/4)
3
    建⽴立類別和xib的關連(包含物件和事件)




             有多種⽅方法......
3
    確定接⼝口是否正確建⽴立
4
                                              ViewController.m


    #import "ViewController.h"

    @implementation ViewController


    - (IBAction)btn1Click:(id)sender
    {
        [self.view bringSubviewToFront:myImageView01];
    }

    - (IBAction)btn2Click:(id)sender
    {
        [self.view bringSubviewToFront:myImageView02];
    }
同樣範例

(改⽤用純粹 coding)
Project QV056


採⽤用 coding 的⽅方式完成
圖⽚片物件 UIImageView、
UIImage
產⽣生圖⽚片 UIImage,                   ViewController.m (1/3)
            並置⼊入 UIImageView 內

- (void)viewDidLoad
{
    [super viewDidLoad];

!   // 設定第⼀一張圖
    UIImage *myImage01 = [UIImage imageNamed:@"image01.jpg"];
    myImageView01 = [[UIImageView alloc] initWithImage:myImage01];
    myImageView01.frame = CGRectMake(50, 40, 220, 290);
    [self.view addSubview:myImageView01];

    // 設定第⼆二張圖
    UIImage *myImage02 = [UIImage imageNamed:@"image02.jpg"];
    myImageView02 = [[UIImageView alloc] initWithImage:myImage02];
    myImageView02.frame = CGRectMake(50, 40, 220, 290);
    [self.view addSubview:myImageView02];

    ........以下省略 (⾒見下⾴頁).......
}
ViewController.m (2/3)
- (void)viewDidLoad
{
    ........以上省略 (⾒見上⾴頁).......


    // 設定第⼀一個按鈕
     UIButton *myButton01 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     myButton01.frame = CGRectMake(40, 370, 100, 40);
     [myButton01 setTitle:@"Image 01" forState:UIControlStateNormal];
     [myButton01 addTarget:self action:@selector(btn1Click:)
          forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:myButton01];

    // 設定第⼆二個按鈕
    UIButton *myButton02 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton02.frame = CGRectMake(180, 370, 100, 40);
    [myButton02 setTitle:@"Image 02" forState:UIControlStateNormal];
    [myButton02 addTarget:self action:@selector(btn2Click:)
         forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:myButton02];

}
ViewController.m (3/3)




- (void) btn1Click: (id)sender
{
    [self.view bringSubviewToFront:myImageView01];
}

- (void) btn2Click: (id)sender
{
    [self.view bringSubviewToFront:myImageView02];
}
延伸學習

• 查詢 UIImageView、UIButton 還有哪些屬
 性可以設定

• 查詢 UIButton 的事件除了按下之外,還
 有哪些事件可以設定

• 還有哪些 UI 元件,例如 UILable......等
Organizer - Document
在 xib 中顯⽰示 Quick Help
在程式編輯介⾯面快速顯⽰示
      在關鍵字下按 option 鍵
............

Weitere ähnliche Inhalte

Was ist angesagt?

09 UITableView and UITableViewController
09 UITableView and UITableViewController09 UITableView and UITableViewController
09 UITableView and UITableViewControllerTom Fan
 
DoozyUI_基礎介紹教學
DoozyUI_基礎介紹教學DoozyUI_基礎介紹教學
DoozyUI_基礎介紹教學River Wang
 
C++ Builder Basic
C++ Builder BasicC++ Builder Basic
C++ Builder BasicYKLee3434
 
C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic YKLee3434
 
Beyond Android Views - Window,Surface,Special Views,and More
Beyond Android Views - Window,Surface,Special Views,and MoreBeyond Android Views - Window,Surface,Special Views,and More
Beyond Android Views - Window,Surface,Special Views,and Morerogeryi
 
13 UIPopoverController and Modal View Controller
13 UIPopoverController and Modal View Controller13 UIPopoverController and Modal View Controller
13 UIPopoverController and Modal View ControllerTom Fan
 

Was ist angesagt? (11)

09 UITableView and UITableViewController
09 UITableView and UITableViewController09 UITableView and UITableViewController
09 UITableView and UITableViewController
 
DoozyUI_基礎介紹教學
DoozyUI_基礎介紹教學DoozyUI_基礎介紹教學
DoozyUI_基礎介紹教學
 
Borland C++Builder 入門課程
Borland C++Builder 入門課程Borland C++Builder 入門課程
Borland C++Builder 入門課程
 
C++ Builder Basic
C++ Builder BasicC++ Builder Basic
C++ Builder Basic
 
Borland C++Builder 進階課程
Borland C++Builder 進階課程Borland C++Builder 進階課程
Borland C++Builder 進階課程
 
C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic
 
I os 09
I os 09I os 09
I os 09
 
Inside VCL
Inside VCLInside VCL
Inside VCL
 
Beyond Android Views - Window,Surface,Special Views,and More
Beyond Android Views - Window,Surface,Special Views,and MoreBeyond Android Views - Window,Surface,Special Views,and More
Beyond Android Views - Window,Surface,Special Views,and More
 
13 UIPopoverController and Modal View Controller
13 UIPopoverController and Modal View Controller13 UIPopoverController and Modal View Controller
13 UIPopoverController and Modal View Controller
 
I os 16
I os 16I os 16
I os 16
 

Andere mochten auch

Pop shenouda iii
Pop shenouda iiiPop shenouda iii
Pop shenouda iiiShady Noman
 
M tsuchiya+jsoc applphys+2016-03-19
M tsuchiya+jsoc applphys+2016-03-19M tsuchiya+jsoc applphys+2016-03-19
M tsuchiya+jsoc applphys+2016-03-19masaru168
 
M tsuchiya+qrec 2015-01-08
M tsuchiya+qrec 2015-01-08M tsuchiya+qrec 2015-01-08
M tsuchiya+qrec 2015-01-08masaru168
 
M tsuchiya+osaka u+2015 12-18 v2
M tsuchiya+osaka u+2015 12-18 v2M tsuchiya+osaka u+2015 12-18 v2
M tsuchiya+osaka u+2015 12-18 v2masaru168
 

Andere mochten auch (9)

I os 15
I os 15I os 15
I os 15
 
I os 02
I os 02I os 02
I os 02
 
Google 街景
Google 街景Google 街景
Google 街景
 
Monir
MonirMonir
Monir
 
I os 08
I os 08I os 08
I os 08
 
Pop shenouda iii
Pop shenouda iiiPop shenouda iii
Pop shenouda iii
 
M tsuchiya+jsoc applphys+2016-03-19
M tsuchiya+jsoc applphys+2016-03-19M tsuchiya+jsoc applphys+2016-03-19
M tsuchiya+jsoc applphys+2016-03-19
 
M tsuchiya+qrec 2015-01-08
M tsuchiya+qrec 2015-01-08M tsuchiya+qrec 2015-01-08
M tsuchiya+qrec 2015-01-08
 
M tsuchiya+osaka u+2015 12-18 v2
M tsuchiya+osaka u+2015 12-18 v2M tsuchiya+osaka u+2015 12-18 v2
M tsuchiya+osaka u+2015 12-18 v2
 

Ähnlich wie I os 01

07 View Controllers
07 View Controllers07 View Controllers
07 View ControllersTom Fan
 
UIKit Framework
UIKit FrameworkUIKit Framework
UIKit FrameworkRyan Chung
 
Android 智慧型手機程式設計
Android 智慧型手機程式設計Android 智慧型手機程式設計
Android 智慧型手機程式設計Kyle Lin
 
Actionscript遊戲元素
Actionscript遊戲元素Actionscript遊戲元素
Actionscript遊戲元素智傑 楊
 
2016輕鬆開發自有網路地圖工作坊 進階班 0701
2016輕鬆開發自有網路地圖工作坊 進階班 07012016輕鬆開發自有網路地圖工作坊 進階班 0701
2016輕鬆開發自有網路地圖工作坊 進階班 0701family
 
Silverlight 2.0 完全新手學堂,基礎入門 10 大招
Silverlight 2.0 完全新手學堂,基礎入門 10 大招Silverlight 2.0 完全新手學堂,基礎入門 10 大招
Silverlight 2.0 完全新手學堂,基礎入門 10 大招Chui-Wen Chiu
 
01 A Simple iOS Application
01 A Simple iOS Application01 A Simple iOS Application
01 A Simple iOS ApplicationTom Fan
 
掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001rainx1982
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Gelis Wu
 
Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件吳錫修 (ShyiShiou Wu)
 
15 Subclassing UITableViewCell
15 Subclassing UITableViewCell15 Subclassing UITableViewCell
15 Subclassing UITableViewCellTom Fan
 
Buildout
BuildoutBuildout
Buildoutiaiyang
 
製作 Unity Plugin for iOS
製作 Unity Plugin for iOS製作 Unity Plugin for iOS
製作 Unity Plugin for iOSJohnny Sung
 
12 Camera
12 Camera12 Camera
12 CameraTom Fan
 

Ähnlich wie I os 01 (20)

07 View Controllers
07 View Controllers07 View Controllers
07 View Controllers
 
UIKit Framework
UIKit FrameworkUIKit Framework
UIKit Framework
 
005
005005
005
 
I os 05
I os 05I os 05
I os 05
 
Android 智慧型手機程式設計
Android 智慧型手機程式設計Android 智慧型手機程式設計
Android 智慧型手機程式設計
 
Chinese hans
Chinese hansChinese hans
Chinese hans
 
testing leads fix for ppt2
testing leads fix for ppt2testing leads fix for ppt2
testing leads fix for ppt2
 
Chinese hans
Chinese hansChinese hans
Chinese hans
 
Actionscript遊戲元素
Actionscript遊戲元素Actionscript遊戲元素
Actionscript遊戲元素
 
2016輕鬆開發自有網路地圖工作坊 進階班 0701
2016輕鬆開發自有網路地圖工作坊 進階班 07012016輕鬆開發自有網路地圖工作坊 進階班 0701
2016輕鬆開發自有網路地圖工作坊 進階班 0701
 
I os 14
I os 14I os 14
I os 14
 
Silverlight 2.0 完全新手學堂,基礎入門 10 大招
Silverlight 2.0 完全新手學堂,基礎入門 10 大招Silverlight 2.0 完全新手學堂,基礎入門 10 大招
Silverlight 2.0 完全新手學堂,基礎入門 10 大招
 
01 A Simple iOS Application
01 A Simple iOS Application01 A Simple iOS Application
01 A Simple iOS Application
 
掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
 
Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件
 
15 Subclassing UITableViewCell
15 Subclassing UITableViewCell15 Subclassing UITableViewCell
15 Subclassing UITableViewCell
 
Buildout
BuildoutBuildout
Buildout
 
製作 Unity Plugin for iOS
製作 Unity Plugin for iOS製作 Unity Plugin for iOS
製作 Unity Plugin for iOS
 
12 Camera
12 Camera12 Camera
12 Camera
 

Mehr von 信嘉 陳

Mehr von 信嘉 陳 (17)

Processing 06
Processing 06Processing 06
Processing 06
 
Processing 05
Processing 05Processing 05
Processing 05
 
Processing 04
Processing 04Processing 04
Processing 04
 
Processing 03
Processing 03Processing 03
Processing 03
 
Processing 02
Processing 02Processing 02
Processing 02
 
Processing 01
Processing 01Processing 01
Processing 01
 
Processing 09
Processing 09Processing 09
Processing 09
 
Processing 08
Processing 08Processing 08
Processing 08
 
Processing 07
Processing 07Processing 07
Processing 07
 
I os 06
I os 06I os 06
I os 06
 
I os 04
I os 04I os 04
I os 04
 
I os 13
I os 13I os 13
I os 13
 
I os 11
I os 11I os 11
I os 11
 
I os 03
I os 03I os 03
I os 03
 
課程規畫
課程規畫課程規畫
課程規畫
 
社群網站 Facebook
社群網站 Facebook社群網站 Facebook
社群網站 Facebook
 
網路搜尋
網路搜尋網路搜尋
網路搜尋
 

I os 01

  • 2. 課程⼤大綱 • 介紹、開發需求、開始 iOS 程式 • 置放按鈕,彈出視窗顯⽰示⽂文字 (UIButton +UIAlertView) • QV053:⽤用程式碼寫作 • QV054:⽤用 xib 畫⾯面連接 • 學習圖⽚片的顯⽰示 • 按鈕切換圖⽚片 (UIImageView) • QV055:使⽤用 xib • QV056:使⽤用程式碼編寫
  • 4. 請認清楚這些名詞 Apple Macintosh iPhone Mac iMac iPad Mac Pro Leopard (10.5) iPod Touch Snow Leopard (10.6) MacBook Lion (10.7) MBP MBA Mountain Lion (10.8) Mac OS X iOS
  • 6. 硬體需求 Mac電腦 (Intel CPU) Mac OSX (最新版本 10.8) iPhone、iPad、iPod Touch (⾮非必須) iOS (最新版本 6.0)
  • 7. Mac 電腦 http://store.apple.com/tw
  • 9. ⿊黑蘋果 (不建議) 使⽤用⾮非 Apple 的硬體安裝 Mac OS X 安裝困難 不穩定 昇級問題重重 缺乏完整的⽤用⼾戶使⽤用經驗
  • 10. 虛擬機器 (不建議) 在 PC 內使⽤用虛擬機器軟體 (VM) 模擬 Mac 速度慢 操作不⽅方便 沒有完整的⽤用⼾戶使⽤用經驗
  • 11. 開發軟體 (唯⼀一選擇) • xcode • 開發編輯器 • iOS SDK • iOS 模擬器 Interface Builder Instruments https://developer.apple.com/xcode/
  • 12. 開發者帳號 價格: US$ 99 / 年 (個⼈人帳號) US$ 399 /  年 (公司帳號) 功能: 線上資源查詢整合 上傳⾄至實機測試 App上架發佈
  • 14. xcode 下載、安裝 執⾏行 開新專案 在模擬器中執⾏行
  • 15. 預設範本為 開新專案選擇 iOS Single View Application
  • 16. 專案名稱 公司識別 檔名前置⽂文字 (空⽩白) 設定裝置 Storyboards (暫不使⽤用) ⾃自動記憶體管理 (使⽤用)
  • 18. 執⾏行功能 屬性設定、連接設定 主要開發編寫介⾯面 檔案區 偵錯輸出 元件選擇
  • 21. 範例: 置放按鈕,按下後 彈出視窗顯⽰示⽂文字 QV053:⽤用程式碼寫作 QV054:⽤用 xib 畫⾯面連接
  • 23.
  • 24.
  • 25.
  • 26.
  • 28. 在主畫⾯面載⼊入後執⾏行 ViewController.m (1/2) - (void)viewDidLoad { [super viewDidLoad]; ! // Do any additional setup after loading the view, typically from a nib. UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(100, 350, 120, 45); [myButton setTitle:@"按我" forState:UIControlStateNormal]; [myButton addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:myButton]; } (1) 宣告⼀一個按鈕 (2) 設定位置 (3) 設定標題⽂文字 (4) 指定按下後執⾏行的程式 (5) 置於在畫⾯面上
  • 29. ViewController.m (2/2) - (void)onClick:(id)sender { NSLog(@"You click the Button!"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello World" message:@"你按了按鈕" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }
  • 30. UIButton 的樣式 試驗⼀一下:按鈕的其他樣式 UIButtonTypeRoundedRect (圓⾓角⽅方形按鈕) UIButtonTypeDetailDisclosure (細節顯⽰示) UIButtonTypeInfoLight (⽩白⾊色資訊 i) UIButtonTypeInfoDark (深⾊色資訊 i) UIButtonTypeContactAdd (加號按鈕) UIButtonTypeCustom (使⽤用者⾃自訂)
  • 32. Project QV054 同 Project QV053,但採⽤用 xib  的⽅方式設計畫⾯面 設定 xib 畫⾯面與類別的連接 按鈕物件 UIButton 警告顯⽰示 UIAlertView
  • 33.
  • 34. 步驟⼀一:在 .h 檔案進⾏行宣告 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIButton *myButton; } 宣告在此類別, - (IBAction)onClick:(id)sender; 會需要的資料或元件 @end
  • 35. 步驟⼆二:在 .xib 檔案佈置 ViewController.xib (2) 設定必要屬性 (1) 拖移進⼊入畫⾯面擺放
  • 36. 建⽴立『物件』的關連 按住 Ctrl 鍵 再⽤用滑⿏鼠由 "File's Owner" 拉到 "按鈕"
  • 37. 建⽴立『事件』的關連 按住 Ctrl 鍵 再⽤用滑⿏鼠由 "按鈕" 拉到 "File's Owner"
  • 39. 步驟三:在 .m 檔案實作程式 ViewController.m - (void)viewDidLoad { [super viewDidLoad]; ! // Do any additional setup after loading the view, typically from a nib. } - (IBAction)onClick:(id)sender { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello World" message:@"你按了按鈕" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }
  • 41. 圖形的使⽤用 • 圖檔以 .png 檔最佳 (.jpg 亦可) • 事先處理好圖檔的⼤大⼩小尺⼨寸 • 圖檔必須先加⼊入⾄至專案內 • 搭配 UIImage 及 UIImageView 使⽤用
  • 42. 範例:按鈕切換圖⽚片 QV055:使⽤用 xib QV056:使⽤用程式碼編寫
  • 43. Project QV055 採⽤用 xib  的⽅方式設計畫⾯面 圖⽚片物件 UIImageView
  • 44.
  • 45. 0 準備好圖⽚片,將圖⽚片移⼊入專案內
  • 46. 0
  • 47. 0 可以另建 Group 分類整理檔案
  • 48. 0 Group 為專案內的整理 和實際存放的資料夾無關
  • 49. 1 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIImageView *myImageView01; IBOutlet UIImageView *myImageView02; } - (IBAction)btn1Click:(id)sender; - (IBAction)btn2Click:(id)sender; @end
  • 50. 2 ViewController.xib (1/4)
  • 51. 2 ViewController.xib (2/4)
  • 52. 2 ViewController.xib (3/4)
  • 53. 2 ViewController.xib (4/4)
  • 54. 3 建⽴立類別和xib的關連(包含物件和事件) 有多種⽅方法......
  • 55. 3 確定接⼝口是否正確建⽴立
  • 56. 4 ViewController.m #import "ViewController.h" @implementation ViewController - (IBAction)btn1Click:(id)sender { [self.view bringSubviewToFront:myImageView01]; } - (IBAction)btn2Click:(id)sender { [self.view bringSubviewToFront:myImageView02]; }
  • 58. Project QV056 採⽤用 coding 的⽅方式完成 圖⽚片物件 UIImageView、 UIImage
  • 59. 產⽣生圖⽚片 UIImage, ViewController.m (1/3) 並置⼊入 UIImageView 內 - (void)viewDidLoad { [super viewDidLoad]; ! // 設定第⼀一張圖 UIImage *myImage01 = [UIImage imageNamed:@"image01.jpg"]; myImageView01 = [[UIImageView alloc] initWithImage:myImage01]; myImageView01.frame = CGRectMake(50, 40, 220, 290); [self.view addSubview:myImageView01]; // 設定第⼆二張圖 UIImage *myImage02 = [UIImage imageNamed:@"image02.jpg"]; myImageView02 = [[UIImageView alloc] initWithImage:myImage02]; myImageView02.frame = CGRectMake(50, 40, 220, 290); [self.view addSubview:myImageView02]; ........以下省略 (⾒見下⾴頁)....... }
  • 60. ViewController.m (2/3) - (void)viewDidLoad { ........以上省略 (⾒見上⾴頁)....... // 設定第⼀一個按鈕 UIButton *myButton01 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton01.frame = CGRectMake(40, 370, 100, 40); [myButton01 setTitle:@"Image 01" forState:UIControlStateNormal]; [myButton01 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:myButton01]; // 設定第⼆二個按鈕 UIButton *myButton02 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton02.frame = CGRectMake(180, 370, 100, 40); [myButton02 setTitle:@"Image 02" forState:UIControlStateNormal]; [myButton02 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:myButton02]; }
  • 61. ViewController.m (3/3) - (void) btn1Click: (id)sender { [self.view bringSubviewToFront:myImageView01]; } - (void) btn2Click: (id)sender { [self.view bringSubviewToFront:myImageView02]; }
  • 62.
  • 63. 延伸學習 • 查詢 UIImageView、UIButton 還有哪些屬 性可以設定 • 查詢 UIButton 的事件除了按下之外,還 有哪些事件可以設定 • 還有哪些 UI 元件,例如 UILable......等
  • 65. 在 xib 中顯⽰示 Quick Help
  • 66. 在程式編輯介⾯面快速顯⽰示 在關鍵字下按 option 鍵