Wednesday, August 10, 2016

iOS Set Image from URL

We can set image to image view from url by converting content of url in NSData as follow.

in viewDidLoad() add following code

 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
    NSString *strUrl = @"http://www.freedigitalphotos.net/images/img/homepage/87357.jpg";
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
    img.image = [UIImage imageWithData:imageData];

    [self.view addSubview:img];

Also add Following lines to info.plist file for resolve 
Transport security has blocked a cleartext HTTP


NSAppTransportSecurity
NSAllowsArbitraryLoads
     

Upload UIImage as base64 String

Upload UIImage as Base64 String (Upload UIImage as string) //Select Pic From Camera or Gallery       @objc func btnPro...