作者:ACE纞_814 | 来源:互联网 | 2023-09-09 09:05
iPhone实例 实现弹出框视图是本文要介绍的内容,最近项目中需要写复杂的表单,需要添加日期和多选框内容,所以需要弹出视图添加相关信息。这里写一个原型,用来帮助同事做复杂的表单。
模仿的效果:
实现的效果:
实现步骤如下:
创建项目iphone_sprintview
创建一个继承UIView的子类SecondView
创建一个SecondView.xib。
下面打开SecondView.xib,做如下操作:
添加视图
在iphone_sprintviewViewController中添加相应控件的声明。
- IBOutlet UIDatePicker *myDataPicker;
- IBOutlet UIView *myView;
控件关联。
相关的代码: #import
- #import "SecondView.h"
- @interface iphone_sprintviewViewController : UIViewController {
- SecondView *mySecondView;
- IBOutlet UIDatePicker *myDataPicker;
- IBOutlet UIView *myView;
- }
- @property (nonatomic,retain) SecondView *mySecondView;
- @property (nonatomic,retain) UIDatePicker *myDataPicker;
- @property (nonatomic,retain) UIView *myView;
- -(IBAction)onClickButton:(id)sender;
- @end
-
- #import "iphone_sprintviewViewController.h"
- #import <QuartzCore/QuartzCore.h>
- @implementation iphone_sprintviewViewController
- @synthesize mySecondView,myDataPicker,myView;
- -(void) viewDidLoad
- {
- self.mySecondView=[[SecondView alloc] init];
- NSArray *array =[[NSBundle mainBundle] loadNibNamed:@"SecondView"
- owner:self options:nil];
- self.mySecondView=[array objectAtIndex:0];
- //将图层的边框设置为圆脚
- self.myView.layer.cornerRadius = 8;
- self.myView.layer.masksToBounds = YES;
- //给图层添加一个有色边框
- self.myView.layer.borderWidth = 8;
- self.myView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)viewDidUnload {
- self.mySecondView=nil;
- self.myDataPicker=nil;
- self.myView=nil;
- }
- - (void)dealloc {
- [self.myView release];
- [self.mySecondView release];
- [self.myDataPicker release];
- [super dealloc];
- }
- -(IBAction)onClickButton:(id)sender
- {
- if ([sender tag]==0) {
- [self.view addSubview:mySecondView];
- }else if ([sender tag]==1) {
- [mySecondView removeFromSuperview];
- }else {
- NSLog(@"==%@",self.myDataPicker.date);
- [mySecondView removeFromSuperview];
- }
- }
- @end
源代码:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.sprintview/
小结:iPhone实例 实现弹出框视图的内容介绍完了,希望本文对你有所帮助!