SubViews中如果根据tag获取到指点的 UIView – viewWithTag
来源:互联网 发布:在淘宝网上开店步骤 编辑:程序博客网 时间:2024/06/05 00:40
通常我们在初始化页面后,在UIView 上动态的添加多个子 View 时,又没设置类成员变量,在相关的操作中又要使用到那些子视图的控件。这时我们就可以用 viewWithTag 这个方法来获取相关子视图的变量,以方便操作。
类似例子:
UIImageView *leftMsgBg = [[[UIImageViewalloc] initWithFrame:CGRectMake(0, 0, 17, 37)]autorelease];
[leftMsgBg setImage:[UIImageimageNamed:@”bg_camera_left”]];
leftMsgBg.tag = 123;
UIImageView *midMsgBg = [[[UIImageViewalloc] initWithFrame:CGRectMake(17, 0, 85, 37)]autorelease];
// [midMsgBg setImage:[UIImage imageNamed:@"bg_camera"]];
[midMsgBg setBackgroundColor:[UIColorgrayColor]];
midMsgBg.tag = 124;
UIImageView *rightMsgBg = [[[UIImageViewalloc] initWithFrame:CGRectMake(102, 0, 17, 37)]autorelease];
[rightMsgBg setImage:[UIImageimageNamed:@”bg_camera_right”]];
rightMsgBg.tag = 125;
UILabel * lab = [[[UILabelalloc]initWithFrame:CGRectMake(20, 0, 65, 37)]autorelease];
lab.text = @”新消息!!!”;
lab.tag = 126;
[lab setFont:[UIFontboldSystemFontOfSize:14]];
[lab setBackgroundColor:[UIColorclearColor]];
[lab setTextColor:[UIColoryellowColor]];
[self.newMsgBgaddSubview:leftMsgBg];
[self.newMsgBgaddSubview:midMsgBg];
[self.newMsgBgaddSubview:rightMsgBg];
[self.newMsgBgaddSubview:lab];
UIImageView *leftMsgBg = (UIImageView *)[self.newMsgBgviewWithTag:123];
UIImageView *midMsgBg = (UIImageView *)[self.newMsgBgviewWithTag:124];
UILabel * lab = (UILabel *)[self.newMsgBgviewWithTag:126];
文章作者:zxwo0o
本文地址:http://www.xmsdn.net/iso/viewwithtag/
版权所有 © 转载时必须以链接形式注明作者和原始出处!
- SubViews中如果根据tag获取到指点的 UIView – viewWithTag
- Swift中使用Xib获取UIView控件,结果UIView控件的subViews为nil
- UIView 中Clip Subviews不起作用?
- viewWithTag 获取的文档
- UIView viewWithTag:
- uiview viewwithtag
- UIView的viewWithTag方法的使用
- iOS根据UIVIew获取当前的UIViewController
- 根据tag获取view
- cocoa touch——UIView——superview subviews window tag
- 设置UIView透明度不影响subViews透明度的方法
- ios 移除UIView上所有的subViews
- 根据tag获取控件,并且根据两个控件的tag交换控件图片
- 根据TableViewCell的subviews得到对应的TableViewCell以及NSIndexPath
- Autoresize UIView to fit subviews
- 用 [UIView viewwithTag]程序崩溃
- UIView-tag
- 想要动态的在UIView的subviews的指定位置插入和删除某个subview怎么办
- 操作引入xml文件的书包(定位到指定节点)
- ie 浏览器无法保存cookie,且与域名包含了下划线(_)有关系的问题
- 异步上传文件插件-ajaxfileupload.js简单例子
- psch和ssch的作用在WCDMA
- 域名解析中A记录、CNAME、MX记录、NS记录的区别和联系
- SubViews中如果根据tag获取到指点的 UIView – viewWithTag
- 通讯录的实现
- 两种方法测试大小端
- Zend Framework2使用Faq随记
- android如何手动生成设备节点
- [protobuf] 开源点评:Protocol Buffers介绍
- Java日期操作常用方法
- yii2ecommerce 手册
- 安卓service需要注意的东西