【发布时间】:2014-11-19 20:03:13
【问题描述】:
我目前有以下代码可以在我的 iOS 应用程序中加载用户的个人资料图片。但是,这是我重写的,以便从 url 加载它。
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
NSURL *url = [NSURL URLWithString:@"http://placehold.it/250x250"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 50.0;
imageView.layer.borderColor = [UIColor whiteColor].CGColor;
imageView.layer.borderWidth = 3.0f;
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
imageView.layer.shouldRasterize = YES;
imageView.clipsToBounds = YES;
旧代码有这个UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)];,这样图像就不会太大。如何将其合并到我的代码中?
并且将http://placehold.it/250x250 更改为http://placehold.it/100x100 不是一种选择,因为这只是一个占位符。
【问题讨论】:
标签: ios objective-c xcode uiimageview