iPhone实例 实现弹出框视图

移动开发 iOS
本文介绍的是iPhone实例 实现弹出框视图,一个简单的小实例,我们来看实现内容。

iPhone实例 实现弹出框视图是本文要介绍的内容,最近项目中需要写复杂的表单,需要添加日期和多选框内容,所以需要弹出视图添加相关信息。这里写一个原型,用来帮助同事做复杂的表单。

模仿的效果:

iPhone实例 实现弹出框视图

实现的效果:

iPhone实例 实现弹出框视图

实现步骤如下:

创建项目iphone_sprintview

创建一个继承UIView的子类SecondView

创建一个SecondView.xib。

下面打开SecondView.xib,做如下操作:

iPhone实例 实现弹出框视图

添加视图

iPhone实例 实现弹出框视图 

iPhone实例 实现弹出框视图

在iphone_sprintviewViewController中添加相应控件的声明。

  1. IBOutlet UIDatePicker *myDataPicker;   
  2. IBOutlet UIView *myView; 

控件关联。

CocoaChina

相关的代码: #import <UIKit/UIKit.h>

  1. #import "SecondView.h"   
  2. @interface iphone_sprintviewViewController : UIViewController {   
  3.     SecondView *mySecondView;   
  4.     IBOutlet UIDatePicker *myDataPicker;   
  5.     IBOutlet UIView *myView;   
  6. }   
  7. @property (nonatomic,retain) SecondView *mySecondView;   
  8. @property (nonatomic,retain) UIDatePicker *myDataPicker;   
  9. @property (nonatomic,retain) UIView *myView;   
  10. -(IBAction)onClickButton:(id)sender;   
  11. @end   
  12.  
  13. #import "iphone_sprintviewViewController.h"   
  14. #import <QuartzCore/QuartzCore.h>   
  15. @implementation iphone_sprintviewViewController   
  16. @synthesize mySecondView,myDataPicker,myView;   
  17. -(void) viewDidLoad   
  18. {   
  19.     self.mySecondView=[[SecondView alloc] init];   
  20.     NSArray *array =[[NSBundle mainBundle] loadNibNamed:@"SecondView"   
  21.                                                   owner:self options:nil];   
  22.     self.mySecondView=[array objectAtIndex:0];   
  23.     //将图层的边框设置为圆脚   
  24.     self.myView.layer.cornerRadius = 8;   
  25.     self.myView.layer.masksToBounds = YES;   
  26.     //给图层添加一个有色边框   
  27.     self.myView.layer.borderWidth = 8;   
  28.     self.myView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];   
  29. }   
  30. - (void)didReceiveMemoryWarning {   
  31.     [super didReceiveMemoryWarning];   
  32. }   
  33. - (void)viewDidUnload {   
  34.     self.mySecondView=nil;   
  35.     self.myDataPicker=nil;   
  36.     self.myView=nil;   
  37. }   
  38. - (void)dealloc {   
  39.     [self.myView release];   
  40.     [self.mySecondView release];   
  41.     [self.myDataPicker release];   
  42.     [super dealloc];   
  43. }   
  44. -(IBAction)onClickButton:(id)sender   
  45. {   
  46.     if ([sender tag]==0) {   
  47.         [self.view addSubview:mySecondView];   
  48.     }else if ([sender tag]==1) {   
  49.         [mySecondView removeFromSuperview];   
  50.     }else {   
  51.         NSLog(@"==%@",self.myDataPicker.date);   
  52.         [mySecondView removeFromSuperview];   
  53.     }   
  54. }   
  55. @end 

源代码:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.sprintview/

小结:iPhone实例 实现弹出框视图的内容介绍完了,希望本文对你有所帮助!

责任编辑:zhaolei 来源: CocoaChina
相关推荐

2011-07-22 17:40:46

IOS

2011-08-18 10:32:13

iPhone编程视图

2011-08-19 10:39:01

iPhone App输入面板

2011-07-28 10:11:54

iPhone开发 备忘

2011-07-27 11:19:33

iPhone UITableVie

2009-09-23 15:12:41

Hibernate视图

2011-08-11 17:32:51

iPhone视图

2011-08-12 11:23:47

iPhone窗口视图

2011-07-29 10:51:41

iPhone 全屏显示 视图

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-07-07 15:32:07

2009-08-28 17:51:40

iPhone多视图开发

2011-08-08 16:56:44

iPhone 字符处理 视图

2009-12-11 15:35:50

PHP弹出对话框

2011-08-12 10:04:24

iPhone开发视图

2011-08-15 18:02:32

iPhone开发表视图

2011-07-22 15:32:53

iPhone 按钮 对话框

2011-07-06 16:15:46

iPhone 图片

2011-07-18 13:37:53

2011-07-18 15:32:14

iPhone 录音 播放
点赞
收藏

51CTO技术栈公众号