Skip to content

Instantly share code, notes, and snippets.

@thoretton-edwin
Last active August 29, 2015 13:56
Show Gist options
  • Save thoretton-edwin/9016132 to your computer and use it in GitHub Desktop.
Save thoretton-edwin/9016132 to your computer and use it in GitHub Desktop.
iOS ImageView by file or url
// imgV1 is a UIImageView
-(IBAction)addImageView:(id)sender
{
NSLog(@"add image from repo");
if(imgV1==nil)
{
//just @"name" for png , other: @"name.extension"
UIImage* img = [UIImage imageNamed:@"image.jpg"];
imgV1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
//imgV1.contentMode = UIViewContentModeScaleAspectFill;
//imgV1.contentMode = UIViewContentModeScaleToFill;
//imgV1.contentMode = UIViewContentModeScaleAspectFill;
imgV1.contentMode = UIViewContentModeScaleAspectFit;
imgV1.image = img;
[self.view addSubview:imgV1];
}
}
-(IBAction)addUrlImageView:(id)sender
{
NSLog(@"add image from repo");
if(imgV1!=nil)
{
NSURL* imgUrl = [NSURL URLWithString:@"http://www.rockers.es/Portals/12/img/6136_1280x1024.jpg"];
NSData* data = [[NSData alloc] initWithContentsOfURL:imgUrl];
UIImage* img = [UIImage imageWithData:data];
imgV1.image=img;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment