Search code examples
xcode4uiimageview

Attempt to programmatically re-position UIImageView


**UPDATED QUESTION TO REFLECT ADDITION OF "INIT" IN UIIMAGEVIEW ALLOC*** I have "imageView" as a variable, declared already in my ".h" class. I am forced in a particular case to programmatically move "imageView" up by about 10 pixels and have experienced no luck. In looking at the current UIImageView ("imageView) position, I determined the X/Y/WIDTH/HEIGHT should be (78,214,170,120). Below is the code I am working with, which works but displays no UIImageView/UIImage:

imageView = [[UIImageView alloc]init];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:img2String]]];
imageView.frame = CGRectMake(78,214,170,120);     
imageView.image = image;

I'd appreciate any help.


Solution

  • You should initialize your image view first

    imageView = [[UIImageView alloc] init];
    

    like above.