[英]Changing the colour of UIView that is created dynamically
I am creating a UIView
and its subviews (such as UITextfield, UIButton etc.) dynamically( by reading from JSON ) 我正在动态创建UIView
及其子视图(例如UITextfield,UIButton等)(通过从JSON读取)
I am giving tags to all UIView
and try to call by tag. 我给所有UIView
标签,并尝试通过标签调用。
For instance I am trying to change the background colour of a view inside another view. 例如,我试图更改另一个视图内部的视图的背景色。
parent view's tag is 1, subview's is 11. 父视图的标签为1,子视图的标签为11。
My sample code is as follows; 我的示例代码如下;
UIView *temp = [self.view viewWithTag:1];
if([[temp viewWithTag:11] isKindOfClass:[UIView class]])
{
[((UIView*)[temp viewWithTag:11]) setBackgroundColor:[UIColor blackColor]];
}
But there is no change, no effect. 但是没有改变,没有效果。
Could you please help me on solving this. 您能帮我解决这个问题吗?
#define PARENT_VIEW_TAG 1
#define CHILD_VIEW_TAG 11
UIView *parentView = [self.view viewWithTag:PARENT_VIEW_TAG];
for (UIView *vw in [parentView subviews]) {
if(vw.tag == CHILD_VIEW_TAG)
{
[vw setBackgroundColor:[UIColor blackColor]];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.