SubViews中如果根据tag获取到指点的 UIView – viewWithTag
2015-03-20 16:42
633 查看
通常我们在初始化页面后,在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/
版权所有 © 转载时必须以链接形式注明作者和原始出处!
类似例子:
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/
版权所有 © 转载时必须以链接形式注明作者和原始出处!
相关文章推荐
- viewWithTag获取subview规则详解
- viewWithTag获取subview规则详解
- viewWithTag 获取的文档
- viewWithTag获取subview规则详解
- iOS开发笔记--viewWithTag获取subview规则详解
- UIView viewWithTag:
- 根据tag获取view
- 用 [UIView viewwithTag]程序崩溃
- iOS开发笔记--viewWithTag获取subview规则详解
- viewWithTag获取subview规则详解
- ListView解决图片错乱为什弱引用相关比findViewWithTag效率要高?
- 如何根据View获取所在的Controller
- viewWithTag
- uiview的删除,原来 view 的tag可以起相同的名字,
- iOS 局部变量 setTag后可在别的地方调用 viewWithTag
- xcode6.1 UITableView viewWithTag
- 如何根据View获取所在的Controller
- [转载]Flip an image in UIImageView using UIView transitionWithView
- Android ListView异步加载图片错位解决方案一 使用findViewWithTag
- uiscrollview UIView 设置背景图片 swift 不用colorWithPatternImage