iphone实现弹出框视图

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

模仿的效果:

image

实现的效果:

image

 

实现步骤如下:

  • 创建项目iphone_sprintview
  • 创建一个继承UIView的子类SecondView
  • 创建一个SecondView.xib。
  • 下面打开SecondView.xib,做如下操作:

image

添加视图:

image image

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

IBOutlet UIDatePicker *myDataPicker; 
IBOutlet UIView *myView;

  • 控件关联。

image

  • 相关的代码:
  • #import <UIKit/UIKit.h> 
    #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/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值