9..IOS学习:用UIWindow自定义AlertView(最基本代码)

[cpp]  view plain copy
  1. //  
  2. //  ABCustomAlertView.h  
  3. //  KnowledgeChoice  
  4. //  
  5. //  Created by  on 13-6-19.  
  6. //  Copyright (c) 2013年 DoubleMan. All rights reserved.  
  7. //  自定义相应的控件及代理就可以用了。。  
  8.   
  9. #import   
  10.   
  11. @interface ABCustomAlertView UIWindow  
  12.   
  13. // 显示  
  14. (void)show;  
  15. // 消失  
  16. (void)dismiss;  
  17.   
  18. @end  

[cpp]  view plain copy
  1. //  
  2. //  ABCustomAlertView.m  
  3. //  KnowledgeChoice  
  4. //  
  5. //  Created by on 13-6-19.  
  6. //  Copyright (c) 2013年 DoubleMan. All rights reserved.  
  7. //  
  8.   
  9. #import "ABCustomAlertView.h"  
  10.   
  11. @implementation ABCustomAlertView  
  12.   
  13. (id)initWithFrame:(CGRect)frame  
  14.  
  15.     self [super initWithFrame:frame];  
  16.     if (self)  
  17.         // Initialization code  
  18.         self.windowLevel UIWindowLevelAlert;  
  19.         // 这里,不能设置UIWindow的alpha属性,会影响里面的子view的透明度,这里我们用一张透明的图片  
  20.         // 设置背影半透明  
  21.         self.backgroundColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"alert_bg.png"]];  
  22.   
  23.           
  24.         UIView *view [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)] autorelease];  
  25.         view.backgroundColor [UIColor blackColor];  
  26.         view.center CGPointMake(160, 240);  
  27.   
  28.         [self addSubview:view];  
  29.      
  30.       
  31.     return self;  
  32.  
  33.   
  34. (void)show  
  35.     [self makeKeyAndVisible];  
  36.  
  37.   
  38. (void)dismiss  
  39.     [self resignKeyWindow];  
  40.     [self release];  
  41.  
  42.   
  43. (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  
  44.     // 点击消失  
  45.     [self dismiss];  
  46.  
  47.   
  48. (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  
  49.       
  50.  
  51.   
  52. (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event  
  53.       
  54.  
  55.   
  56. @end  

这只是基本的思路,调用的时候只要调show和dismiss就可以显示、消失了。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值