#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton * btn = [self createBtn:YES andCGRectMake:CGRectMake(, , , )];
[btn setTitle:@"长度" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
btn.backgroundColor = [UIColor cyanColor];
btn.tag = ;
[self.view addSubview:btn]; UIButton * btn1 = [self createBtn:YES andCGRectMake:CGRectMake(, , , )];
btn1.tag = ;
btn1.selected = NO;
[btn1 setTitle:@"长度长度" forState:UIControlStateNormal]; //循环btn btn的背景图片不能更改
/*
UIImageView * image = [[UIImageView alloc]init];
image.backgroundColor = [UIColor orangeColor];
UIImageView * image1 = [[UIImageView alloc]init];
image1.backgroundColor = [UIColor yellowColor];
[btn1 setImage:image.image forState:UIControlStateNormal];
[btn1 setImage:image1.image forState:UIControlStateSelected];
*/
[btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
[btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor = [UIColor cyanColor];
[self.view addSubview:btn1];
} -(void)pressBtn:(UIButton*)sender{
//循环btn btn的背景图片不能更改
if (sender.tag == ) {
for (id obj in sender.subviews) {
if ([obj isKindOfClass:[UIImageView class]])
{
if (sender.selected) {
UIImageView* image = (UIImageView*)obj;
image.backgroundColor = [UIColor redColor]; sender.selected = NO;
}
else{
UIImageView* image = (UIImageView*)obj;
image.backgroundColor = [UIColor grayColor];
sender.selected = YES;
}
}
}
}
else{
for (id obj in sender.subviews) {
if ([obj isKindOfClass:[UIImageView class]])
{
if (sender.selected) {
UIImageView* image = (UIImageView*)obj;
image.backgroundColor = [UIColor redColor]; sender.selected = NO;
}
else{
UIImageView* image = (UIImageView*)obj;
image.backgroundColor = [UIColor grayColor];
sender.selected = YES; }
}
}
}
}
-(UIButton*)createBtn:(BOOL)yes andCGRectMake:(CGRect)frame{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = frame;
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(btn.titleLabel.frame.size.width/+btn.frame.size.width/+, , , )];
image.backgroundColor = [UIColor redColor];
[btn addSubview:image]; return btn; }

循环btn上面的视图的更多相关文章

  1. 给View添加手势,防止点击View上其他视图触发点击效果

    在开发过程中,我们可能会遇到这个问题. 当我们给一个view添加了手势,但是我们又不想点击view上面的视图也触发手势.如下图: 我们在红色view上添加了手势,但是又不想点击黄色view也触发.其实 ...

  2. iOS for循环创建button,button的宽度依据上面的文字来自适应.

    近期须要使用一个标签页,寻思自己写一个demo. 标签的大小依据上面的文字来自适应大小,须要依据后台返回的数据自己主动换行.没有加入 NSArray *arr = @[@"无知", ...

  3. n=n+1 放在print(s)的上面的影响 (2) n=n=+1在前面,则不满足前面<100条件时候,才跳出while的循环,这时候while循环结束, 到了外面的下一步-->print()

    1+2+3+....+100=     ? n=1 s = 0 while n < =100: s = s+n n= n+1 # n=n+1    在print(s)上面的情况 print(s)

  4. jq源码解析之绑在$,jQuery上面的方法

    1.当我们用$符号直接调用的方法.在jQuery内部是如何封装的呢?有没有好奇心? // jQuery.extend 的方法 是绑定在 $ 上面的. jQuery.extend( { //expand ...

  5. 如何批量清除128组节点db上面的过期的binlog,释放磁盘空间。(转)

    如果10台以内的db的话,自己手动ssh进去,clean就足以,但是上百台呢,就要写脚本了.大概思路:在 一台db跳转机上面, 写一个脚本,访问slave,远程获取正在复制的master上面的binl ...

  6. 清理:db上面的过期的binlog,释放磁盘空间。 (转)

    如果10台以内的db的话,自己手动ssh进去,clean就足以,但是上百台呢,就要写脚本了.大概思路:在 一台db跳转机上面, 写一个脚本,访问slave,远程获取正在复制的master上面的binl ...

  7. k-develop 在ros上面的应用

    sudo apt-get install kdevelop 根据wiki上面的ros 章节中,关于kdevelop的介绍,配置好环境即可. 导入工程时,选中src/src下面的章节,不过,需要注意去掉 ...

  8. 获取Linux进程运行在哪个CPU内核上面的方法

    首先,当某些时候,在一段程序或者借助第三方软件进行程序协助的时候,在性能的优化,以及程序bug的排除上面,可能会想知道该程序执行的进程被调度到了哪一个CPU内核进行工作,从而可以推断是否是受限于硬件还 ...

  9. IQKeyboardManager在某个页面取消键盘上面的Toolbar

    使用IQKeyboardManager的时候,如果想在某个页面取消键盘上面的Toolbar,请使用如下方法,按控制器去操作 // 取消IQKeyboardManager Toolbar [[IQKey ...

随机推荐

  1. .net学习之.net和C#关系、运行过程、数据类型、类型转换、值类型和引用类型、数组以及方法参数等

    1..net 和 C# 的关系.net 是一个平台,C#是种语言,C#语言可以通过.net平台来编写.部署.运行.net应用程序,C#通过.net平台开发.net应用程序2..net平台的重要组成FC ...

  2. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. struts2文件上传类型的过滤

    转自:http://www.2cto.com/kf/201403/282787.html 第一种解决方案: 1.手动实现文件过滤: 判断上传的文件是否在允许的范围内定义该Action允许上传的文件类型 ...

  4. Android:dimen尺寸资源文件的使用

    dimen.xml在values文件夹下面 <resources> <!-- Default screen margins, per the Android Design guide ...

  5. Effective C++笔记:设计与声明

    条款18:让接口容易被正确使用,不易被误用 1,好的接口很容易被正确使用,不容易被误用.你应该在你的所有接口中努力达成这些性质. 2,“促进正使用”的办法包括接口的一致性,以及与内置类型的行为兼容. ...

  6. Loadrunner中web_custom_request使用场景

    其中有一段从服务器段动态返回的字符串需要重新提交给服务器(见红色标注) 录制自动生成的脚本是: web_submit_data("generateYfLstAction.do",  ...

  7. Python核心模块——urllib模块

    现在Python基本入门了,现在开始要进军如何写爬虫了! 先把最基本的urllib模块弄懂吧. urllib模块中的方法 1.urllib.urlopen(url[,data[,proxies]]) ...

  8. Storm Grouping —— 流分组策略

    Storm Grouping: Shuffle Grouping :随机分组,尽量均匀分布到下游Bolt中 将流分组定义为混排.这种混排分组意味着来自Spout的输入将混排,或随机分发给此Bolt中的 ...

  9. android开发 BaseAdapter中getView()里的3个参数是什么意思

    BaseAdapter适配器里有个getView()需要重写public View getView(int position,View converView,ViewGroup parent){ // ...

  10. JS URL传中文参数引发的乱码问题

    今天的项目中碰到了一个乱码问题,从JS里传URL到服务器,URL中有中文参数,服务器里读出的中文参数来的全是“?”,查了网上JS编码相关资料得以解决. 解决方法一: 1.在JS里对中文参数进行两次转码 ...