Last active
August 29, 2015 13:56
-
-
Save thoretton-edwin/9016132 to your computer and use it in GitHub Desktop.
iOS ImageView by file or url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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