重写AlertView(用block)
@interface AlertView : UIView
@property (nonatomic,copy) void(^block)(UIColor *color);
- (id)initWithAlertView;
- (void)showTwo;
@end
自定义View的.m文件
- (id)initWithAlertView
{
self = [super init];//自定义init方法 就是重写了系统的init方法;
if (self)
{
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.backgroundColor = [UIColor redColor];
btn1.frame = CGRectMake(5, 100, 40, 25);
[btn1 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn1];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.backgroundColor = [UIColor greenColor];
btn2.frame = CGRectMake(150, 100, 40, 25);
[btn2 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn2];
}
return self;
}
- (void)btn1Click:(UIButton *)btn
{
self.block(btn.backgroundColor);
[self removeFromSuperview];
}
- (void)btn2Click:(UIButton *)btn
{
self.block(btn.backgroundColor);
[self removeFromSuperview];
}
主界面的.m
- (IBAction)buttonClick:(id)sender
{
AlertView *alertView = [[AlertView alloc] initWithAlertView];
alertView.backgroundColor = [UIColor grayColor];
alertView.frame = CGRectMake(100, 100, 200, 130);
// [alertView initWithAlertView];
[self.view addSubview:alertView];
__block ViewController *vc = self;
alertView.block = ^(UIColor *color){
vc.view.backgroundColor = color;
};
// [alertView showTwo];要不要都行 看情况而定
}
重写AlertView(用block)的更多相关文章
- 用block响应button的点击事件
1.继承UIButton : 2.在自己定义的button类中的方法 addTarget:(id)target action:(SEL)action forControlEvents:(UIContr ...
- django模板复用 extends,block,include
template复用 extends block include render 参考:https://code.ziqiangxuetang.com/django/django-template.ht ...
- Django模板之模板继承(extends/block)
Django模版引擎中最强大也是最复杂的部分就是模版继承了.模版继承可以让您创建一个基本的“骨架”模版,它包含您站点中的全部元素,并且可以定义能够被子模版覆盖的 block. 模板继承: 1. ...
- Object-c Associated Object
oc的关联的作用在我看来就是将两个对象关联起来,用的时候通过key和对象把和这个对象关联的对象再取出来(我做的项目就是和UITableView里面的一个属性关联起来了) 举个栗子: - (void)v ...
- 【读书笔记】--《编写高质量iOS与OS X代码的52个有效方法》
1.Objective-C 起源: 在 C 语言基础上添加了面向对象特性,是 C 语言的超集.Objective-C 由 SmallTalk 语言演变过来,使用消息结构,运行环境由运行环境决定. OC ...
- Django模板的继承
一.extend 1.extend继承模板 2.一个文件中只能继承一个模板 3.extend继承模板中的所有内容,模板的内容包括:html的head和body ,eg:
- Effective Objective-C 2.0 — 第10条:在既有类中使用关联对象存放自定义数据
可以通过“关联对象”机制来把两个对象连起来 定义关联对象时可指定内存管理语义,用以模仿定义属性时所采用的“拥有关系”与“非拥有关系” 只有在其他做法不可行时才应选用关联对象,因为这种做法通常会引入难于 ...
- PHP模版引擎 – Twig
在网站开发过程中模版引擎是必不可少的,PHP中用的最多的当属Smarty了.目前公司系统也是用的Smarty,如果要新增一个页面只需把网站的头.尾和左侧公共部分通过Smarty的include方式引入 ...
- 编写高质量iOS代码与OS X代码的effective 方法小结
一.熟悉OC: 了解OC的起源: OC和C++,Java等面向对象语言类似,不过有很方面差别.因为该语言使用 消息结构而非函数调用. 消息结构和函数调用的区别:前者是在其运行时所应执行的代码由运行环 ...
随机推荐
- Python学习笔记_Chapter 6定制数据对象
1. 有用的BIF a. 判断字符串中是否包含子字符串 if s_a in s_b: b. pop() 描述:从指定的列表位置删除并返回一个数据项. (sarah_name,sarah_dob)=l_ ...
- Java 中值传递和引用传递 区分
详细参见 http://blog.csdn.net/zzp_403184692/article/details/8184751
- CDOJ 1270 Playfair(模拟)
题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...
- 简单介绍移动端CSS3单位rem的用法
PC端大部份是用px单位,小部分用em单位,而移动端,请全部用rem单位吧.目前大部份设备,包括但不限于iOS 5+.Android 2.3+.Window Phone 8+都是可以兼容的,具体兼容表 ...
- Java 水仙花数
小小练习大神掠过吧 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数&quo ...
- oracle 11g高级 安装图解(摘自网络)
使用的高级安装 启动OUI后出现“选择安装方式”窗口,我们选择:高级安装 步骤3:出现“选择安装类型”窗口,选择我们需要安装的版本.我们在此肯定是选择企业版. 至于产品语言不用选择,它会根据当前系统的 ...
- SharePoint 2013 工作流设计之Designer 使用“可视化视图
转载自:http://www.cnblogs.com/jianyus/p/3406309.html SharePoint 2013增强了工作流功能,而Designer里面也添加了可视化设计视图,也就是 ...
- erlang nif小结
一.nif获取string参数的两种方式 1.eif_get_string 实例如下: static ERL_NIF_TERM erl_sm4_encrypt(ErlNifEnv* env, int ...
- 查询全国的省市信息<option>拼接
//修改页面获取省市信息 function getProvinceUSER_AREA1(){ $.ajax({ type:'post', url:'<%=path%>/user/findU ...
- quicksort快排
废话不多说,上代码: void quicksort(int x[], int lo, int hi){ int i = lo, j = hi; ]; while(i <= j){ while(x ...