简体   繁体   English

uiimageview无法使用URLWithString:

[英]uiimageview is not Working using URLWithString:

_profileImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@".../images/Profile/Pratik Maniya Photo.jpg"]]];

我想使用代码中的URL链接显示图像,但是没有任何结果。

The problem is in the spaces symbols in url. 问题出在url中的空格符号中。

You can use: 您可以使用:

stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]

Full code: 完整代码:

NSString *base_url = @"https://safesocpgm.000webhostapp.com/images/Profile/Pratik Maniya Photo.jpg";
NSString* encoded_url = [base_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
_profileImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:encoded_url]]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM