本文主要是介绍IOS 用UIWindow自定义AlertView(最基本代码),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- //
- // ABCustomAlertView.h
- // KnowledgeChoice
- //
- // Created by on 13-6-19.
- // Copyright (c) 2013年 DoubleMan. All rights reserved.
- // 自定义相应的控件及代理就可以用了。。
- #import <UIKit/UIKit.h>
- @interface ABCustomAlertView : UIWindow
- // 显示
- - (void)show;
- // 消失
- - (void)dismiss;
- @end
- //
- // 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
这篇关于IOS 用UIWindow自定义AlertView(最基本代码)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!