这在 UIImageView 上不使用 AFNetworking 的类别方法时有效,但我意识到 AF 可能会覆盖所做的任何事情,因为这是异步发生的:
这是在我的自定义 UITableViewCell 中(自己是单元格):
NSURL *url = [NSURL URLWithString:video.thumbnail];
[self.imageView setImageWithURL:url
placeholderImage:[UIImage imageNamed:@"Logo.png"]];
// not working
CALayer *layer = [self.imageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0];
也尝试将它放在调用 setImageWithURL 之前。
这是我现在拥有的,它不是圆角:
NSURL *url = [NSURL URLWithString:_video.thumbnail];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeHolder = [UIImage imageNamed:@"Logo"];
__weak UIImageView *imageView = self.thumbnail;
[self.thumbnail setImageWithURLRequest:request placeholderImage:placeHolder success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
imageView.image = image;
// round the edges of the video thumbnail
CALayer *layer = [imageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:8.0];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"couldn't load image: %@", [error localizedDescription]);
}];