美文网首页程序员
UIView的tag属性

UIView的tag属性

作者: 每日总结 | 来源:发表于2016-03-12 09:31 被阅读907次

tag属性是一个快捷取视图的方法,需要先对视图设置tag属性,然后就能通过viewWithTag:方法来取用;

UIView *aView = [[UIView alloc] init];
aView.tag = 101;
[self.window addSubview:aView];
[aView release];

[self.window viewWithTag:101].backgroundColor = [UIColor redColor];

tag属性在对象创建之后就可以设置,但是要取用它,必须先将这个视图放入其父视图的数组中;
viewWithTag可以取用所有子视图组以及子视图的子视图组

#define kGetView(tag) [self.view viewWithTag:tag]

相关文章

网友评论

    本文标题:UIView的tag属性

    本文链接:https://www.haomeiwen.com/subject/meqtlttx.html