Enviar pesquisa
Carregar
I os 03
•
1 gostou
•
605 visualizações
信嘉 陳
Seguir
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 47
Recomendados
I os 11
I os 11
信嘉 陳
Angular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app example
Alexey Frolov
004
004
Stronger Shen
Taming forms with React
Taming forms with React
GreeceJS
Effective Android Data Binding
Effective Android Data Binding
Eric Maxwell
Modern Android Architecture
Modern Android Architecture
Eric Maxwell
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
Darwin Durand
Android Testing
Android Testing
Evan Lin
Recomendados
I os 11
I os 11
信嘉 陳
Angular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app example
Alexey Frolov
004
004
Stronger Shen
Taming forms with React
Taming forms with React
GreeceJS
Effective Android Data Binding
Effective Android Data Binding
Eric Maxwell
Modern Android Architecture
Modern Android Architecture
Eric Maxwell
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
Darwin Durand
Android Testing
Android Testing
Evan Lin
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
Darwin Durand
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
Fwdays
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
Fwdays
Awesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom Libraries
FITC
iOS
iOS
Scott Leberknight
Константин Чернухо_Popups, alerts and windows
Константин Чернухо_Popups, alerts and windows
GeeksLab Odessa
Window object methods (timer related)
Window object methods (timer related)
Shivani Thakur Daxini
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
martinlippert
Dmytro Zaitsev Viper: make your mvp cleaner
Dmytro Zaitsev Viper: make your mvp cleaner
Аліна Шепшелей
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
UA Mobile
Angular Mini-Challenges
Angular Mini-Challenges
Jose Mendez
Muster in Webcontrollern
Muster in Webcontrollern
Jens Himmelreich
Standford 2015 week9
Standford 2015 week9
彼得潘 Pan
AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
taobao.com
ハンズオン資料 電話を作ろう(v2.x用)
ハンズオン資料 電話を作ろう(v2.x用)
Kenji Sakashita
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
DroidConTLV
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependências
Marcelo Aymone
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
I os 16
I os 16
信嘉 陳
I os 02
I os 02
信嘉 陳
Mais conteúdo relacionado
Mais procurados
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
Darwin Durand
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
Fwdays
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
Fwdays
Awesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom Libraries
FITC
iOS
iOS
Scott Leberknight
Константин Чернухо_Popups, alerts and windows
Константин Чернухо_Popups, alerts and windows
GeeksLab Odessa
Window object methods (timer related)
Window object methods (timer related)
Shivani Thakur Daxini
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
martinlippert
Dmytro Zaitsev Viper: make your mvp cleaner
Dmytro Zaitsev Viper: make your mvp cleaner
Аліна Шепшелей
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
UA Mobile
Angular Mini-Challenges
Angular Mini-Challenges
Jose Mendez
Muster in Webcontrollern
Muster in Webcontrollern
Jens Himmelreich
Standford 2015 week9
Standford 2015 week9
彼得潘 Pan
AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
taobao.com
ハンズオン資料 電話を作ろう(v2.x用)
ハンズオン資料 電話を作ろう(v2.x用)
Kenji Sakashita
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
DroidConTLV
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependências
Marcelo Aymone
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
Mais procurados
(20)
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
Awesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom Libraries
iOS
iOS
Константин Чернухо_Popups, alerts and windows
Константин Чернухо_Popups, alerts and windows
Window object methods (timer related)
Window object methods (timer related)
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
Dmytro Zaitsev Viper: make your mvp cleaner
Dmytro Zaitsev Viper: make your mvp cleaner
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
Angular Mini-Challenges
Angular Mini-Challenges
Muster in Webcontrollern
Muster in Webcontrollern
Standford 2015 week9
Standford 2015 week9
AngularJS.part1
AngularJS.part1
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
ハンズオン資料 電話を作ろう(v2.x用)
ハンズオン資料 電話を作ろう(v2.x用)
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependências
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Destaque
I os 16
I os 16
信嘉 陳
I os 02
I os 02
信嘉 陳
I os 04
I os 04
信嘉 陳
I os 14
I os 14
信嘉 陳
課程規畫
課程規畫
信嘉 陳
I os 07
I os 07
信嘉 陳
I os 15
I os 15
信嘉 陳
I os 06
I os 06
信嘉 陳
I os 09
I os 09
信嘉 陳
I os 08
I os 08
信嘉 陳
I os 05
I os 05
信嘉 陳
I os 10
I os 10
信嘉 陳
I os 13
I os 13
信嘉 陳
Destaque
(13)
I os 16
I os 16
I os 02
I os 02
I os 04
I os 04
I os 14
I os 14
課程規畫
課程規畫
I os 07
I os 07
I os 15
I os 15
I os 06
I os 06
I os 09
I os 09
I os 08
I os 08
I os 05
I os 05
I os 10
I os 10
I os 13
I os 13
Semelhante a I os 03
Anyone can play iPhone-Tuzhiwu
Anyone can play iPhone-Tuzhiwu
Xiaochun Shen
Leaving Interface Builder Behind
Leaving Interface Builder Behind
John Wilker
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Mobivery
Quick Start to iOS Development
Quick Start to iOS Development
Jussi Pohjolainen
Custom UIViewController Transitions
Custom UIViewController Transitions
Jan Ilavsky
201104 iphone navigation-based apps
201104 iphone navigation-based apps
Javier Gonzalez-Sanchez
20180721 code defragment
20180721 code defragment
Chiwon Song
Your Second iPhone App - Code Listings
Your Second iPhone App - Code Listings
Vu Tran Lam
iOS_Presentation
iOS_Presentation
Emannuel Carvalho
iOS Beginners Lesson 4
iOS Beginners Lesson 4
Calvin Cheng
Net conf BG xamarin lecture
Net conf BG xamarin lecture
Tsvyatko Konov
Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019
DanielJalkut
IOS APPs Revision
IOS APPs Revision
Muhammad Amin
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
彼得潘 Pan
Creating Container View Controllers
Creating Container View Controllers
Bob McCune
iOS for ERREST - alternative version
iOS for ERREST - alternative version
WO Community
Migrating Objective-C to Swift
Migrating Objective-C to Swift
Elmar Kretzer
From mvc to viper
From mvc to viper
Krzysztof Profic
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
Droidcon Berlin
Swift ui userinput
Swift ui userinput
joonjhokil
Semelhante a I os 03
(20)
Anyone can play iPhone-Tuzhiwu
Anyone can play iPhone-Tuzhiwu
Leaving Interface Builder Behind
Leaving Interface Builder Behind
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Quick Start to iOS Development
Quick Start to iOS Development
Custom UIViewController Transitions
Custom UIViewController Transitions
201104 iphone navigation-based apps
201104 iphone navigation-based apps
20180721 code defragment
20180721 code defragment
Your Second iPhone App - Code Listings
Your Second iPhone App - Code Listings
iOS_Presentation
iOS_Presentation
iOS Beginners Lesson 4
iOS Beginners Lesson 4
Net conf BG xamarin lecture
Net conf BG xamarin lecture
Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019
IOS APPs Revision
IOS APPs Revision
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Creating Container View Controllers
Creating Container View Controllers
iOS for ERREST - alternative version
iOS for ERREST - alternative version
Migrating Objective-C to Swift
Migrating Objective-C to Swift
From mvc to viper
From mvc to viper
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
Swift ui userinput
Swift ui userinput
Mais de 信嘉 陳
Processing 06
Processing 06
信嘉 陳
Processing 05
Processing 05
信嘉 陳
Processing 04
Processing 04
信嘉 陳
Processing 03
Processing 03
信嘉 陳
Processing 02
Processing 02
信嘉 陳
Processing 01
Processing 01
信嘉 陳
Processing 09
Processing 09
信嘉 陳
Processing 08
Processing 08
信嘉 陳
Processing 07
Processing 07
信嘉 陳
I os 01
I os 01
信嘉 陳
Google 街景
Google 街景
信嘉 陳
社群網站 Facebook
社群網站 Facebook
信嘉 陳
網路搜尋
網路搜尋
信嘉 陳
Mais de 信嘉 陳
(13)
Processing 06
Processing 06
Processing 05
Processing 05
Processing 04
Processing 04
Processing 03
Processing 03
Processing 02
Processing 02
Processing 01
Processing 01
Processing 09
Processing 09
Processing 08
Processing 08
Processing 07
Processing 07
I os 01
I os 01
Google 街景
Google 街景
社群網站 Facebook
社群網站 Facebook
網路搜尋
網路搜尋
I os 03
1.
Class 03 iOS 應⽤用軟體設計
2.
課程⼤大綱 •
⽂文字的輸⼊入 (UITextField) • QV061:BMI 計算 • UISwitch, UISlider • QV005:UISwitch 及 UISlider 基本⽤用法 • QV013:利⽤用三個 UISlider 改變背景⾊色 • UIView • QV074:UIView (Container) • 以程式語法產⽣生各種 UIView 元件 • QV075:只是擺放 • QV076:程式語⾔言的⽅方式 • Samples:UICatalog
3.
⽂文字的輸⼊入 UITextField ⽂文字
4.
Project QV061 輸⼊入⾝身⾼高和體重,計算 BMI 之值 UITextField
使⽤用
5.
ViewController.h @interface ViewController :
UIViewController { IBOutlet UITextField *textHeight, *textWeight; IBOutlet UILabel *display; } - (IBAction) calcBMI:(id)sender; - (IBAction) doneEdit:(id)sender; @end
6.
ViewController.xib
7.
ViewController.m - (IBAction) calcBMI:(id)sender {
float h = [[textHeight text] floatValue]; float w = [textWeight.text floatValue]; float bmi = w / ((h/100)*(h/100)); display.text = [NSString stringWithFormat:@"%5.2f", bmi]; }
8.
虛擬鍵盤不會隱藏的問題解決
要注意各個 UITextFiled 的 Did End On Exit 事件 要指定動作,以隱藏輸⼊入鍵盤 - (IBAction) doneEdit:(id)sender { [sender resignFirstResponder]; }
9.
與鍵盤按鍵有關的⼩小問題 - (IBAction) calcBMI:(id)sender {
float h = [[textHeight text] floatValue]; float w = [textWeight.text floatValue]; float bmi = w / ((h/100)*(h/100)); display.text = [NSString stringWithFormat:@"%5.2f", bmi]; [textHeight resignFirstResponder]; 隱藏輸⼊入鍵盤 [textWeight resignFirstResponder]; } - (IBAction) doneEdit:(id)sender { [sender resignFirstResponder]; } 設定鍵盤類型 - (void)viewDidLoad { [super viewDidLoad]; [textHeight setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; [textWeight setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; }
10.
數值,開關資料的輸⼊入
11.
UISlider 類別 • 主要屬性
• value • minimumValue • maximumValue • continuous
12.
UISwitch 類別 • 主要屬性
• on 開關的狀態 (BOOL值)
13.
範例:QV005 UISlider
及 UISwitch 基本⽤用法
14.
Project QV005 UI 元件
Slider UI 元件 Switch
15.
ViewController.h #import <UIKit/UIKit.h> @interface ViewController
: UIViewController { IBOutlet UILabel *messageSlider; IBOutlet UILabel *messageSwitch; } ViewController.xib -(IBAction)changeSlider:(id)sender; -(IBAction)changeSwitch:(id)sender; @end
16.
ViewController.xib
17.
#import "ViewController.h"
ViewController.m @implementation ViewController -(IBAction)changeSlider:(id)sender { UISlider *thisSlider = (UISlider *)sender; int number = (int)(thisSlider.value); NSString *msg = [[NSString alloc] initWithFormat:@"%d", number]; messageSlider.text = msg; } -(IBAction)changeSwitch:(id)sender { UISwitch *thisSwitch = (UISwitch *)sender; if(thisSwitch.on) { messageSwitch.text = @"ON"; } else { messageSwitch.text = @"OFF"; } } @end
18.
範例:QV013
利⽤用三個 UISlider 改變背景⾊色
19.
Project QV013 三組
UISlider 更換背景顏⾊色 早期知名的⼿手電筒程式
20.
ViewController.h
注意此數值需與 程式互相配合 三個都執⾏行同⼀一段函式
21.
ViewController.h #import <UIKit/UIKit.h> @interface ViewController
: UIViewController { IBOutlet UISlider *sliderR; IBOutlet UISlider *sliderG; IBOutlet UISlider *sliderB; } @property (retain, nonatomic) IBOutlet UISlider *sliderR; @property (retain, nonatomic) IBOutlet UISlider *sliderG; @property (retain, nonatomic) IBOutlet UISlider *sliderB; -(IBAction)sliderChange:(id)sender; @end
22.
ViewController.m
顏⾊色的值為 -(IBAction)sliderChange:(id)sender 0 到 1 之間的浮點數 { float valueR = [sliderR value]; float valueG = [sliderG value]; float valueB = [sliderB value]; UIColor *myColor = [UIColor colorWithRed:(valueR/255.0) green:(valueG/255.0) blue:(valueB/255.0) alpha: 1]; self.view.backgroundColor = myColor; }
23.
範例:QV074
UIView 的包容 (container) 處理
24.
Project QV074 利⽤用 UIView
包容多個 UIView ⼦子物件 UISwitch 及 UISlider UIView 物件位置移動
25.
ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UISwitch *mySwitch; IBOutlet UIView *myView; IBOutlet UISlider *mySlider1, *mySlider2; IBOutlet UILabel *myLabel1, *myLabel2; } - (IBAction) changeSwitch:(id)sender; - (IBAction) changeSlider:(id)sender; @end 將多個物件包在⼀一塊
26.
ViewController.xib 注意物件擺放的層次關係
27.
ViewController.m (1/2)
切換 UISwitch 以控制 UIView, 會整個顯⽰示或隱藏 - (IBAction) changeSwitch:(id)sender { UISwitch *thisSwitch = (UISwitch *)sender; if(thisSwitch.on) { 內部宣告明確類別的物 myView.hidden = NO; } 件,取得傳⼊入的指標 else { myView.hidden = YES; } } 取得 UISwitch 的輸⼊入 xxxxx.on (BOOL 型態)
28.
ViewController.m (2/2) - (IBAction)
changeSlider:(id)sender { myLabel1.text = [NSString stringWithFormat:@"%3.1f", mySlider1.value]; myLabel2.text = [NSString stringWithFormat:@"%3.1f", mySlider2.value]; float x = 320 * mySlider1.value; float y = 460 * (1.0-mySlider2.value); // 因為不能改寫center.x及center.y。所以改⽅方法 mySwitch.center = CGPointMake(x, y); } 移動 UIView 的位置 取得 UISlider 的輸⼊入 xxxxx.value (float 型態)
29.
各種常⽤用的 UIView 元件
30.
範例:QV075, QV076 以程式語法,產⽣生 UIView
物件 的⽅方式
31.
Project QV075 常⾒見且簡單的畫⾯面元件 只有畫⾯面擺放
32.
Project QV076 以程式置放 UIView
物件 UILabel, UIButton, UITextField, UISlider, UISwitch, UIStepper, UIImageView, UIWebView
33.
ViewController.h #import <UIKit/UIKit.h> @interface ViewController
: UIViewController { UILabel *myLabel; } - (void) textChange:(id)sender; 會讓很多程式⽚片段使 - (void) doneEdit:(id)sender; - (void) buttonClick:(id)sender; ⽤用,故宣告在此 - (void) sliderChange:(id)sender; - (void) switchChange:(id)sender; - (void) stepperChange:(id)sender; @end
34.
ViewController.m (1/9)
UILabel - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UILabel (注意,myLabel已定義在類別中) myLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 200, 30)]; myLabel.textAlignment = UITextAlignmentCenter; myLabel.font = [UIFont fontWithName:@"Arial" size:20]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.text = @"訊息⽂文字列"; [self.view addSubview:myLabel]; }
35.
ViewController.m (2/9)
UIButton + UIAlert - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UIButton UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(30, 70, 72, 37); [myButton setTitle:@"Click me" forState:UIControlStateNormal]; [myButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:myButton]; UIAlertView 使⽤用 } - (void) buttonClick:(id)sender { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"現在狀態" message:@"按下了按鈕" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }
36.
ViewController.m (3/9)
UITextField (1/2) - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UITextField UITextField *myTextField = [[UITextField alloc] init]; myTextField.frame = CGRectMake(30, 120, 100, 31); // ⾼高(31) 為固定值 myTextField.borderStyle = UITextBorderStyleRoundedRect; myTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; myTextField.text = @"預設內容"; myTextField.secureTextEntry = YES; [myTextField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged]; [myTextField addTarget:self action:@selector(doneEdit:) forControlEvents:UIControlEventEditingDidEndOnExit]; [self.view addSubview:myTextField]; } 兩個事件指定
37.
ViewController.m (4/9)
UITextField (2/2) - (void) textChange:(id)sender { UITextField *thisTextField = (UITextField *)sender; if ([thisTextField.text length] == 0) { myLabel.text = @"沒有輸⼊入⽂文字"; } else { myLabel.text = [NSString stringWithFormat:@"⽂文字:%@", thisTextField.text]; } } - (void) doneEdit:(id)sender 取得輸⼊入的內容 { [sender resignFirstResponder]; } 隱藏虛擬鍵盤
38.
ViewController.m (5/9)
UISlider - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UISlider CGRect frame1 = CGRectMake(30, 170, 79, 23); // ⾼高(23) 為固定值 UISlider *mySlider = [[UISlider alloc] initWithFrame:frame1]; mySlider.minimumValue = 0.0; mySlider.maximumValue = 100.0; mySlider.value = 50.0; [mySlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:mySlider]; } - (void) sliderChange:(id)sender { UISlider *thisSlider = (UISlider *)sender; float value = thisSlider.value; 取得輸⼊入的內容 myLabel.text = [NSString stringWithFormat:@"滑桿值為:%5.2f", value]; }
39.
UISwitch
ViewController.m (6/9) - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UISwitch CGRect frame2 = CGRectMake(30, 220, 79, 27); // 寬(79)⾼高(27)為固定值 UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:frame2]; mySwitch.on = NO; [mySwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:mySwitch]; } - (void) switchChange:(id)sender { UISwitch *thisSwitch = (UISwitch *)sender; if(thisSwitch.on) 取得:開或關 { myLabel.text = [NSString stringWithFormat:@"切換鍵為:開 (ON)"]; } else { myLabel.text = [NSString stringWithFormat:@"切換鍵:關 (不是ON)"]; } }
40.
UIStepper
iOS 5 之後提供 ViewController.m (7/9) - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UIStepper CGRect frame3 = CGRectMake(185, 70, 94, 27); // 寬(94)⾼高(27)為固定值 UIStepper *myStepper = [[UIStepper alloc] initWithFrame:frame3]; myStepper.maximumValue = 10.0; myStepper.minimumValue = 0.0; myStepper.value = 5.5; [myStepper setStepValue:0.1]; // 每次改變的量 [myStepper setContinuous:YES]; // 可以按住不放來連續變更 [myStepper setWraps:YES]; // 設定是否循環(到最⼤大值時增加數值,從最⼩小值開始) [myStepper addTarget:self action:@selector(stepperChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:myStepper]; } - (void) stepperChange:(id)sender { UIStepper *thisStepper = (UIStepper *)sender; float value = thisStepper.value; 取得輸⼊入的內容 myLabel.text = [NSString stringWithFormat:@"增減鍵的值為:%4.1f", value]; }
41.
ViewController.m (8/9)
UIImageView - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UIImage UIImage *myImage = [UIImage imageNamed:@"Cat.png"]; // 產⽣生 UIImageView UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage]; myImageView.frame = CGRectMake(185, 120, 128, 128); [self.view addSubview:myImageView]; } 需注意,圖像使⽤用包含 UIImageView (View Control) 及 UIImage (圖檔本⾝身)
42.
ViewController.m (9/9)
UIWebView - (void)viewDidLoad { ****** 省略部份程式碼 ****** // 產⽣生 UIWebView UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(30, 270, 270, 165)]; myWebView.scalesPageToFit = YES; [myWebView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.apple.com"]]]; [self.view addSubview:myWebView]; } 此處為簡略⽤用法
43.
⾃自我練習 熟悉並區分程式⽤用法及 Interface Builder
的⽤用法 此範例提到之 UIView 類別 UILabel UIButton UITextField UISlider UISwitch UIStepper UIImageView UIWebView
44.
範例觀摩 UICatalog
45.
46.
47.
............