ios - UIImageView remains blank -


i created viewcontroller , attached imageviewcontroller it. here interface , implementation. when run program doesn't show image, blank view.

#import <uikit/uikit.h>  @interface imageviewcontroller : uiviewcontroller @property (nonatomic, strong) uiimageview *myimageview;  @end 

implementation

#import "imageviewcontroller.h"  @interface imageviewcontroller ()  @end   @implementation imageviewcontroller  @synthesize myimageview;   - (void)viewdidload {     [super viewdidload];     // additional setup after loading view.     //create image      //create image     uiimage *myscreenshot = [uiimage imagenamed:@"lips_png6197.png"];      //image view instance display image     self.myimageview = [[uiimageview alloc] initwithimage:myscreenshot];      //set frame image view     cgrect myframe = cgrectmake(10.0f, 10.0f, self.myimageview.frame.size.width,                                 self.myimageview.frame.size.height/2);     [self.myimageview setframe:myframe];      //if image bigger frame can scale     [self.myimageview setcontentmode:uiviewcontentmodescaleaspectfit];      //add image view current view     [self.view addsubview:self.myimageview];    }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. } 

note checked uiimage not nil in debugger. not creating uiimageview via ib. suggestions on going wrong i.e. why not seeing image.

if you're not creating image view in ib problem:

 cgrect myframe = cgrectmake(10.0f, 10.0f, self.myimageview.frame.size.width,                                 self.myimageview.frame.size.height/2); 

your telling width , height should based off self.myimageview hasn't been created yet it's 0. here saying:

cgrectmake(10.0f, 10.0f, 0.0, 0.0); 

i'm assuming might want this:

 cgrect myframe = cgrectmake(10.0f, 10.0f, self.view.frame.size.width,                                 self.view.frame.size.height/2); 

Comments