9..IOS学习:用UIWindow自定义AlertView(最基本代码)
2015-09-01 16:58
344 查看
[cpp] view
plaincopy
//
// ABCustomAlertView.h
// KnowledgeChoice
//
// Created by on 13-6-19.
// Copyright (c) 2013年 DoubleMan. All rights reserved.
// 自定义相应的控件及代理就可以用了。。
#import
@interface ABCustomAlertView : UIWindow
// 显示
- (void)show;
// 消失
- (void)dismiss;
@end
[cpp] view
plaincopy
//
// ABCustomAlertView.m
// KnowledgeChoice
//
// Created by on 13-6-19.
// Copyright (c) 2013年 DoubleMan. All rights reserved.
//
#import "ABCustomAlertView.h"
@implementation ABCustomAlertView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.windowLevel = UIWindowLevelAlert;
// 这里,不能设置UIWindow的alpha属性,会影响里面的子view的透明度,这里我们用一张透明的图片
// 设置背影半透明
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"alert_bg.png"]];
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)] autorelease];
view.backgroundColor = [UIColor blackColor];
view.center = CGPointMake(160, 240);
[self addSubview:view];
}
return self;
}
- (void)show {
[self makeKeyAndVisible];
}
- (void)dismiss {
[self resignKeyWindow];
[self release];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// 点击消失
[self dismiss];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
@end
这只是基本的思路,调用的时候只要调show和dismiss就可以显示、消失了。。。
plaincopy
//
// ABCustomAlertView.h
// KnowledgeChoice
//
// Created by on 13-6-19.
// Copyright (c) 2013年 DoubleMan. All rights reserved.
// 自定义相应的控件及代理就可以用了。。
#import
@interface ABCustomAlertView : UIWindow
// 显示
- (void)show;
// 消失
- (void)dismiss;
@end
[cpp] view
plaincopy
//
// ABCustomAlertView.m
// KnowledgeChoice
//
// Created by on 13-6-19.
// Copyright (c) 2013年 DoubleMan. All rights reserved.
//
#import "ABCustomAlertView.h"
@implementation ABCustomAlertView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.windowLevel = UIWindowLevelAlert;
// 这里,不能设置UIWindow的alpha属性,会影响里面的子view的透明度,这里我们用一张透明的图片
// 设置背影半透明
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"alert_bg.png"]];
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)] autorelease];
view.backgroundColor = [UIColor blackColor];
view.center = CGPointMake(160, 240);
[self addSubview:view];
}
return self;
}
- (void)show {
[self makeKeyAndVisible];
}
- (void)dismiss {
[self resignKeyWindow];
[self release];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// 点击消失
[self dismiss];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
@end
这只是基本的思路,调用的时候只要调show和dismiss就可以显示、消失了。。。
相关文章推荐
- HDU 2227 Find the nondecreasing subsequences(DP)
- 7.IOS 8 UIUserNotificationSettings 推送
- 6.UIActionSheet的最后一项点击失效
- iOS UIFont 字体名字大全
- Android Stuido中SVN的设置
- solr query
- **ERROR: Ninja build tool not found.
- UIResponder - 1
- 短语out of the blue
- 关于squirrel的那些事
- deque双向队列
- uva1584 - Circular Sequence
- values v11 v14
- iOS开发-综合UI案例-彩票
- android retrofit @Query用法
- 8.10.3 The MySQL Query Cache
- 被曝红米Note 2屏幕和摄像头偷梁换柱后,小米换图,删帖,发声明
- div设置contentEditable="true"作为文本编辑器,定位光标解决办法
- LeetCode Distinct Subsequences DP
- UILabel圆角、边框、宽度自适应