成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開發常用控件:UIActionSheet和UIAlertView學習

移動開發 iOS
iPhone開發常用控件UIActionSheet和UIAlertView的學習是本文要介紹的內容,主要來學習iphone開發中的控件如何來使用,來看本文詳細內容。

iPhone開發常用控件UIActionSheet和UIAlertView的學習是本文要介紹的內容,主要來學習iphone開發中的控件如何來使用,來看本文詳細內容。

一、UILabel

iPhone開發常用控件

二、UIButton

iPhone開發常用控件

常用事件:Touch Up Inside

三、UITextField

iPhone開發常用控件

常用屬性:

Text:要顯示的文本。

Placeholder:指定將要在文本字段中以灰色顯示的占位符文本。

Clear When Editing Begins:用戶觸摸此字段時是否刪除字段中的值。

Text Input Traits:文本輸入特征。

四、UIImageView

iPhone開發常用控件

常用屬性:

image:指定圖像文件

Mode:圖像在視圖內部的對齊方式以及是否縮放圖像以適應視圖。選擇任何圖像縮放的選項都會潛在地增加處理開銷,因此***避開這些選項,并在導入圖像之前調整好圖像大小。通常Mode屬性為Center。

Alpha:圖像透明度。一般設置為1.0

Background:該屬性繼承自UIView,但它不會影響圖像視圖的外觀,請忽略此屬性。

Drawing復選框:選中Opaque表示視圖后面的任何內容都不應該繪制,并且允許iPhone都繪圖方法通過一些優化來加速繪圖。

Clear Context Before Drawing:選中它之后,iPhone將使用透明黑色繪制控件覆蓋都所有區域,然后才實際繪制控件。考慮到性能問題,并且適用情況很少,通常很少需要選中ClearContext Before Drawing。

Interaction復選框:

User Interaction Enabled:指定用戶能否對此對象進行操作。

Multiple Touch:是否能夠接收多點觸摸事件。

五、UISlider(滑塊)

iPhone開發常用控件

常用屬性:Value Changed

示例:

  1. // 將silder的值反映到sliderLabel   
  2. - (IBAction) sliderValueChanged: (id)sender   
  3. {   
  4.     UISlider *slider = (UISlider *)sender;   
  5.     int progressAsInt = (int)(slider.value + 0.5f);   
  6.     NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];   
  7.     sliderLabel.text = newText;   
  8.     [newText release];   
  9. }  

六、UISwitch(開關)

iPhone開發常用控件

代碼

  1. // 屬性on:獲取開關的狀態是否為on// 方法setOn:設置開關的狀態  
  2. - (IBAction) switchChanged: (id)sender{      
  3. UISwitch *whichSwitch = (UISwitch *)sender;      
  4. BOOL setting = whichSwitch.on;      
  5. [leftSwitch setOn:setting animated:YES];      
  6. [rightSwitch setOn:setting animated:YES];  

七、UISegmentedControl

iPhone開發常用控件

  1. #define kSegmentIndex_Switches   0  
  2. #define kSegmentIndex_Button  1  
  3. - (IBAction) segmentChanged: (id)sender{     
  4.  switch ([sender selectedSegmentIndex])     {        
  5.    case kSegmentIndex_Switches:             
  6.     leftSwitch.hidden = NO;              
  7.     rightSwitch.hidden = NO;              
  8.     doSomethingButton.hidden = YES;              
  9.     break;          
  10.     case kSegmentIndex_Button: leftSwitch.hidden = YES;              
  11.     rightSwitch.hidden = YES;             
  12.      doSomethingButton.hidden = NO;  break;     
  13.   }  

八、UIActionSheet(操作表)和UIAlertView(警報)

UIActionSheet用于迫使用戶在兩個或更多選項之間進行選擇都模式視圖。操作表從屏幕底部彈出,顯示一系列按鈕供用戶選擇,用戶只有單擊了一個按鈕后才能繼續使用使用應用程序。

UIAlertView(警報)以藍色圓角矩形都形式出現在屏幕的中部,警報可顯示一個或多個按鈕。

為了讓控制器類充當操作表的委托,控制器類需要遵從UIActionSheetDelegate協議。我們通過在類聲明都超類之后都尖括號中添加協議名稱來實現。

  1. @interface UntitledViewController : UIViewController      
  2. <UIActionSheetDelegate>{    // ....}// 創建操作表:  
  3. - (IBAction) buttonPressed: (id)sender{     
  4.  UIActionSheet *actionSheet = [[UIActionSheet alloc]     
  5.  initWithTitle:@"Are you sure?" delegate:self    
  6.          cancelButtonTitle:@"Cancel"  
  7.          destructiveButtonTitle:@"Yes,I'm sure."                       
  8.                       otherButtonTitles:nil];  
  9.    [actionSheet showInView:self.view];      
  10.    [actionSheet release];}// 實現方法:#pragma mark ActionSheet Delegate Methods  
  11.    - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{      
  12.       if (buttonIndex != [actionSheet cancelButtonIndex])    {        
  13.         NSString *text = [[NSString alloc] initWithFormat:@"test alert"];          
  14.         UIAlertView *alert = [[UIAlertView alloc]    
  15.         initWithTitle:@"Something was done."   
  16.         message:text   delegate:self   cancelButtonTitle:@"OK!" ,otherButtonTitles:nil];          
  17.         [alert show];          
  18.         [alert release];          
  19.         [text release];     
  20.      }  
  21.  }//- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex//{//    NSLog(@"%d",buttonIndex);//} 

示例

視圖有一個UISegmentedControl,"Switches"下有兩個UISwitch

iPhone開發常用控件

"Button"下有一個“Do Something"的UIButton

iPhone開發常用控件

觸摸"Do Something"Button時彈出UIActionSheet

iPhone開發常用控件

觸摸選擇"Yes,I'm sure."時彈出 UIAlertView

iPhone開發常用控件

  1. OBJECTIVE-C CODE   :UntitledViewController.h   
  2.  //  
  3. //  UntitledViewController.h  
  4. //  Untitled  
  5. //  
  6. //  Created by Elf Sundae on 11/10/10.  
  7. //  Copyright 2010 www.cnBlogs.com/ElfSundae. All rights reserved.  
  8. //  
  9.  
  10. #import <UIKit/UIKit.h> 
  11.  
  12. #define kSegmentIndex_Switches  0  
  13. #define kSegmentIndex_Button      1  
  14.  
  15.  
  16. @interface UntitledViewController : UIViewController  
  17.  <UIActionSheetDelegate> 
  18. {  
  19.  UISwitch * leftSwitch;  
  20.  UISwitch * rightSwitch;  
  21.  UIButton * doSomethingButton;  
  22. }  
  23.  
  24. @property (retain, nonatomic) IBOutlet UISwitch *leftSwitch;  
  25. @property (retain, nonatomic) IBOutlet UISwitch *rightSwitch;  
  26. @property (retain, nonatomic) IBOutlet UIButton *doSomethingButton;  
  27.  
  28. - (IBAction) switchChanged: (id)sender;  
  29. - (IBAction) segmentChanged: (id)sender;  
  30. - (IBAction) buttonPressed: (id)sender;  
  31.  
  32. @end  
  33.  
  34. //  
  35. //  UntitledViewController.h  
  36. //  Untitled  
  37. //  
  38. //  Created by Elf Sundae on 11/10/10.  
  39. //  Copyright 2010 www.cnBlogs.com/ElfSundae. All rights reserved.  
  40. //  
  41. #import <UIKit/UIKit.h> 
  42. #define kSegmentIndex_Switches  0  
  43. #define kSegmentIndex_Button  1  
  44. @interface UntitledViewController : UIViewController  
  45.  <UIActionSheetDelegate> 
  46. {  
  47.  UISwitch * leftSwitch;  
  48.  UISwitch * rightSwitch;  
  49.  UIButton * doSomethingButton;  
  50. }  
  51. @property (retain, nonatomic) IBOutlet UISwitch *leftSwitch;  
  52. @property (retain, nonatomic) IBOutlet UISwitch *rightSwitch;  
  53. @property (retain, nonatomic) IBOutlet UIButton *doSomethingButton;  
  54. - (IBAction) switchChanged: (id)sender;  
  55. - (IBAction) segmentChanged: (id)sender;  
  56. - (IBAction) buttonPressed: (id)sender;  
  57. @end  
  58.  
  59. OBJECTIVE-C CODE   :UntitledViewController.m   
  60.  //  
  61. //  UntitledViewController.m  
  62. //  Untitled  
  63. //  
  64. //  Created by Elf Sundae on 11/10/10.  
  65. //  Copyright 2010 www.cnBlogs.com/ElfSundae. All rights reserved.  
  66. //  
  67.  
  68. #import "UntitledViewController.h"  
  69.  
  70. @implementation UntitledViewController  
  71.  
  72. @synthesize leftSwitch;@synthesize rightSwitch;@synthesize doSomethingButton;// 屬性on:獲取開關的狀態是否為on  
  73. // 方法setOn:設置開關的狀態  
  74. - (IBAction) switchChanged: (id)sender{ UISwitch *whichSwitch = (UISwitch *)sender;   
  75. BOOL setting = whichSwitch.on;   
  76. [leftSwitch setOn:setting animated:YES];   
  77. [rightSwitch setOn:setting animated:YES];  
  78. }  
  79. - (IBAction) segmentChanged: (id)sender{  
  80.  switch ([sender selectedSegmentIndex])  {    
  81.  case kSegmentIndex_Switches:  
  82.    leftSwitch.hidden = NO;     
  83.    rightSwitch.hidden = NO;     
  84.    doSomethingButton.hidden = YES;     
  85.    break;    
  86.    case kSegmentIndex_Button:  
  87.    leftSwitch.hidden = YES;     
  88.    rightSwitch.hidden = YES;     
  89.    doSomethingButton.hidden = NO;   
  90.    break;    
  91. }  
  92. }  
  93. - (IBAction) buttonPressed: (id)sender{ UIActionSheet *actionSheet = [[UIActionSheet alloc]   
  94.  initWithTitle:@"Are you sure?"   
  95.       delegate:self  cancelButtonTitle:@"Cancel"     
  96.       destructiveButtonTitle:@"Yes,I'm sure."  otherButtonTitles:nil];    
  97.       [actionSheet showInView:self.view];   
  98.       [actionSheet release];  
  99.     }  
  100.   - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview.  
  101.  [super didReceiveMemoryWarning];  
  102.  // Release any cached data, images, etc that aren't in use.  
  103. }  
  104.  
  105. - (void)viewDidUnload { // Release any retained subviews of the main view.  
  106.  // e.g. self.myOutlet = nil;  
  107.  self.leftSwitch = nil;   
  108.  self.rightSwitch = nil;   
  109.  self.doSomethingButton = nil;   
  110.  [super viewDidUnload];  
  111. }  
  112.  - (void)dealloc {   
  113.  [leftSwitch release];   
  114.  [rightSwitch release];   
  115.  [doSomethingButton release];   
  116.  [super dealloc];  
  117. }  
  118. #pragma mark   
  119. #pragma mark ActionSheet Delegate Methods  
  120. - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{    
  121. if (buttonIndex != [actionSheet cancelButtonIndex]) {   
  122.  NSString *text = [[NSString alloc] initWithFormat:@"test alert"];   
  123.     UIAlertView *alert = [[UIAlertView alloc]     
  124.     initWithTitle:@"Something was done." message:text     
  125.     delegate:self            
  126.      cancelButtonTitle:@"OK!"  otherButtonTitles:nil];    
  127.      [alert show];    
  128.      [alert release];    
  129.      [text release];   
  130.    }  
  131. }//- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex  
  132. //{  
  133. // NSLog(@"%d",buttonIndex);  
  134. //}  
  135. @end 

小結:iPhone開發常用控件:UIActionSheet和UIAlertView學習的內容介紹完了,希望通過本文的學習能對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

2011-08-01 18:44:16

iPhone開發 UIALertVie UIActionSh

2011-08-22 14:31:53

iPhone開發

2011-07-29 14:48:48

iPhone開發

2011-08-08 10:10:14

iPhone開發 圖片 方法

2011-08-15 10:06:22

iPhone開發nib 文件

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-01 18:27:58

iPhone開發 UISearchBa

2012-04-26 13:23:31

iPhone程序畫面控件調整

2011-08-05 14:48:06

iPhone應用 異步隊列

2011-08-18 10:39:46

iPhone開發界面

2011-08-08 14:57:46

iPhone Autoreleas Property

2013-04-17 11:00:17

Windows PhoWindows Pho

2013-04-17 11:10:02

Windows PhoWindows Pho

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-07-27 11:14:37

iPhone UITableVie

2011-07-27 16:46:04

iPhone iPhone破解 MacPort

2011-08-08 15:56:18

iPhone 震動 NSUserDefa

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-15 17:38:48

iPhone開發調試工具

2011-07-18 14:33:32

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 色爱综合网 | 精品国产欧美一区二区 | 国产成人精品综合 | 爱爱视频在线观看 | 国产精品久久久一区二区三区 | 免费一区二区三区 | 蜜桃传媒av| 免费观看黄色片视频 | 日韩三级在线 | 超碰在线播 | heyzo在线| 99精品欧美一区二区蜜桃免费 | 一级黄色片网站 | 国产做爰| 日批免费在线观看 | 精品伊人久久 | 久草精品在线 | 久久精品网 | 免费一区 | 狠狠操电影 | 黑人久久 | 免费高清av | 高清人人天天夜夜曰狠狠狠狠 | 97国产一区二区精品久久呦 | 国产高清亚洲 | 秋霞电影院午夜伦 | 不卡一区二区三区四区 | 亚洲高清在线 | 美女国内精品自产拍在线播放 | 人人射人人草 | 精品视频一区二区 | 精品国产三级 | 成人国产精品久久 | av性色全交蜜桃成熟时 | 日韩成人免费在线视频 | 在线一区二区三区 | 成人午夜视频在线观看 | 国产成人网 | 国内精品久久久久久影视8 最新黄色在线观看 | 青青草精品 | 在线中文视频 |