码迷,mamicode.com
首页 > 移动开发 > 详细

iOS tag的使用

时间:2016-09-02 09:59:53      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

一、添加标记 (标记不能为0)

UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0,100,100)];
backBtn.backgroundColor = [UIColor blackColor];
backBtn.tag = 666;
[self.view addSubview:backBtn];

二、取出控件

// 方法一
for (UIButton *find_Btn in self.view.subviews) {
        
    if (find_Btn.tag == 666){
        find_Btn.backgroundColor = [UIColor whiteColor];
    }
    if (find_Btn.tag == 999){
        find_Btn.backgroundColor = [UIColor greenColor];
    }
        
 }
// 方法二
UIButton *find_Btn = (UIButton*)[self.view viewWithTag:666]; 
find_Btn.backgroundColor
= [UIColor redColor];

 

iOS tag的使用

标签:

原文地址:http://www.cnblogs.com/xsphehe/p/5832169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!