iPhone开发学习笔记004——自定义背景透明非全屏弹出窗口,子类化UIWindow
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 15:29 点击:次
最终要实现的效果如下,点击上面的按钮可以弹出一个背景透明非全屏的弹出窗口,不使用UIActionSheet和UIAlertView.
新建一个OC类,继承自UIWindow,如下图:
CustomWindow.h:
#import <UIKit/UIKit.h>
@interface CustomWindow :UIWindow {
UIView *superView;
UIView *backgroundView;
UIImageView *backgroundImage;
UIView *contentView;
BOOL closed;
}
@property (nonatomic,retain)UIView *superView;
@property (nonatomic,retain)UIView *backgroundView;
@property (nonatomic,retain)UIImageView *backgroundImage;
@property (nonatomic,retain)UIView *contentView;
-(CustomWindow *)initWithView:(UIView *)aView;
-(void)show;
-(void)close;
@end
CustomWindow.m:
#import "CustomWindow.h"
@implementation CustomWindow
@synthesize superView;
@synthesize backgroundView;
@synthesize backgroundImage;
@synthesize contentView;
-(UIImage *) pngWithPath:(NSString *)path
{
NSString *fileLocation = [[NSBundlemainBundle]pathForResource:path ofType:@"png"];
NSData *imageData = [NSDatadataWithContentsOfFile:fileLoc
下面说说具体过程。
一、新建一个single view application工程,并且添加相关的控件并拖拽连接:
如下图:
新建一个OC类,继承自UIWindow,如下图:
CustomWindow.h:
#import <UIKit/UIKit.h>
@interface CustomWindow :UIWindow {
UIView *superView;
UIView *backgroundView;
UIImageView *backgroundImage;
UIView *contentView;
BOOL closed;
}
@property (nonatomic,retain)UIView *superView;
@property (nonatomic,retain)UIView *backgroundView;
@property (nonatomic,retain)UIImageView *backgroundImage;
@property (nonatomic,retain)UIView *contentView;
-(CustomWindow *)initWithView:(UIView *)aView;
-(void)show;
-(void)close;
@end
CustomWindow.m:
#import "CustomWindow.h"
@implementation CustomWindow
@synthesize superView;
@synthesize backgroundView;
@synthesize backgroundImage;
@synthesize contentView;
-(UIImage *) pngWithPath:(NSString *)path
{
NSString *fileLocation = [[NSBundlemainBundle]pathForResource:path ofType:@"png"];
NSData *imageData = [NSDatadataWithContentsOfFile:fileLoc
相关新闻>>
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
- iPhone开发学习笔记003——UITableViewCell内容自适应高度
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller
- iPhone开发学习笔记006—— NSNotification自定义通知名
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用
- iPhone开发学习笔记008——定制标题三种方法
- 发表评论
-
- 最新评论 更多>>