iPhone實例 實現(xiàn)彈出框視圖
iPhone實例 實現(xiàn)彈出框視圖是本文要介紹的內(nèi)容,最近項目中需要寫復(fù)雜的表單,需要添加日期和多選框內(nèi)容,所以需要彈出視圖添加相關(guān)信息。這里寫一個原型,用來幫助同事做復(fù)雜的表單。
模仿的效果:
實現(xiàn)的效果:
實現(xiàn)步驟如下:
創(chuàng)建項目iphone_sprintview
創(chuàng)建一個繼承UIView的子類SecondView
創(chuàng)建一個SecondView.xib。
下面打開SecondView.xib,做如下操作:
添加視圖
在iphone_sprintviewViewController中添加相應(yīng)控件的聲明。
- IBOutlet UIDatePicker *myDataPicker;
- IBOutlet UIView *myView;
控件關(guān)聯(lián)。
相關(guān)的代碼: #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];
- //將圖層的邊框設(shè)置為圓腳
- 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/
小結(jié):iPhone實例 實現(xiàn)彈出框視圖的內(nèi)容介紹完了,希望本文對你有所幫助!