IPHONE应用开发 - 开发常用控件:UIActionSheet和UIAlertView学习

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学习的内容介绍完了,希望通过本文的学习能对你有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
旋转变压器---数字转换器作为现代伺服系统中被广泛使用的角位置测量系统,大量应用于高精度及大中型数控系统、机器人控制、工业控制、武器火力控制及惯性导航领域中。 传统的角测量系统面临的问题有:体积、重量、功耗偏大,调试、误差补偿试验复杂,费用较高。本文从微型化、智能化的方向进行研究,是解决传统角测量系统所面临问题的好途径。 本文所研究的旋转变压器---数字转换器是由信号调理模块、系统芯片C8051F064和输出控制模块组成的。整个系统的三路输入信号为X=AsinOcosar、Y=Acosθcos ot和Z=Ucosar(基准信号),输出信号为偏转角θ,输出形式为16 位数字量。信号调理模块是由模拟电路组成的,包括信号输入电路、相敏整流电路、滤波电路和直流稳压电源电路,其难点在于相敏整流电路的设计。信号调理模块的主要功能是把输入的交流信号X=AsinOcosor、Y=Acosθcosot转变成直流信号Bsinθ和Bcosθ,并使输出的直流信号在0~2.4V之间;系统芯片C8051F064是CYGNAL公司近年来推出的一款功能齐全的完全集成的混合信号片上系统型单片机。在本文所设计的系统中,系统芯片的输入信号为直流信号Bsinθ和Bcosθ,通过片内自带的2个16位A/D转换器对输入信号的数据进行采样和转换,并对转换完的数据进行滤波处理,以减小由于外界干扰而产生的误差,再用除法和反正切函数解算出偏转角θ的16位数字量;输出控制模块主要完成的功能是通过UARTO向计算机实时发送由单片机计算出来的偏转角度0的16位数字量,而串口的RS-232电平与单片机系统采用的是TTL电平之间的转换所采用的转换芯片是MC1488和MC1489。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值