您的位置:首页 > 其它

iPhone 应用实现弹出框视图的方法

2011-05-17 15:55 267 查看
在 iPhone 上显示大图,或者一屏布置较多内容的话,就需要用到弹出框视图。下面的方法转自 http://wangjun.easymorse.com/?p=1161,希望对开发者有所帮助。

模仿的效果:


实现的效果:


实现步骤如下:
创建项目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

@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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: