UIView的tag属性

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属性)