[英]Changing the colour of UIView that is created dynamically
我正在動態創建UIView
及其子視圖(例如UITextfield,UIButton等)(通過從JSON讀取)
我給所有UIView
標簽,並嘗試通過標簽調用。
例如,我試圖更改另一個視圖內部的視圖的背景色。
父視圖的標簽為1,子視圖的標簽為11。
我的示例代碼如下;
UIView *temp = [self.view viewWithTag:1];
if([[temp viewWithTag:11] isKindOfClass:[UIView class]])
{
[((UIView*)[temp viewWithTag:11]) setBackgroundColor:[UIColor blackColor]];
}
但是沒有改變,沒有效果。
您能幫我解決這個問題嗎?
#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.