簡體   English   中英

添加到子視圖后看不到UIImageView

[英]UIImageView not seen after adding to subview

我試圖創建視圖WRT的JSON data.There在標簽JSON所謂的“類型”數據

{                    
   "type"=text; 
};
       OR 
{
   "type"=image;
};

我將創建類型詳細信息數組,並從該數組創建視圖。**

float y=10;
 for(ViewTypes *type in TypeArray )
{
  if ([type.typeString isEqualToString:@"image"])
{
      NSlog(@"image view is added");       
      UIImageView *imageView=[[UIImageView alloc]init ]; 
      imageView.frame=CGRectMake(55, y, 150, 5);
      imageView.backgroundColor=[UIColor yellowColor];
      [CustomView addSubview:imageView];

      y+=10;

   }
       else if ([type.typeString isEqualToString:@"text"]){
       NSlog(@"text view is added");       
       UITextView *textView=[[UITextView alloc]init ]; 
       textView.frame=CGRectMake(55, y, 150, 5);
       textView.backgroundColor=[UIColor redColor];
       [CustomView addSubview: textView];

       y+=10;
 }
 }

`loop` and if-else  is working fine ,But only `UITextView` is seen in the view and not the `UIImageView`.

UIImageView添加UIImage以顯示它。

if ([type.typeString isEqualToString:@"image"]){
   NSlog(@"image view is added");       
  UIImageView *imageView=[[UIImageView alloc]init ]; 
         imageView.frame=CGRectMake(55, y, 150, 5);
         imageView.backgroundColor=[UIColor yellowColor];
         **[imageView setImage:[UIImage imageNamed:@"imagename.png"]];**
         [CustomView addSubview:imageView];
 y+=10;
}

嘗試這個,

 float y=10;
 for(ViewTypes *type in TypeArray ){

  if ([type.typeString isEqualToString:@"image"]){

        NSlog(@"image view is added");       
      UIImageView *imageView=[[UIImageView alloc]init ]; 
             imageView.frame=CGRectMake(55, y, 150, 5);
             imageView.backgroundColor=[UIColor yellowColor];
             [CustomView addSubview:imageView];
             [CustomView bringSubviewToFront:imageView];

     y+=10;

   }else if ([type.typeString isEqualToString:@"text"]){
       NSlog(@"text view is added");       
       UITextView *textView=[[UITextView alloc]init ]; 
             textView.frame=CGRectMake(55, y, 150, 5);
             textView.backgroundColor=[UIColor redColor];
             [CustomView addSubview: textView];
    y+=10;
 }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM