[英]How do I check what URL an image has been set with?
我使用這樣的url
設置image
:
[self.imageView setMyImageWithURL:[NSURL URLWithString:[trip.destination getHeaderImageUrl] ]];
- (void)setMYImageWithURL:(NSURL *)url {
[self setBackground];
if(url.absoluteString.length >0){
__block UIImageView *safeSelf = self;
UIImage *placeholderImage = [UIImage imageNamed:[NSString stringWithFormat:@"placeholderpic_%@.png", NSLocalizedString(@"LanguageCode" , @"")]];
[self setImageWithURLRequest:[NSURLRequest requestWithURL:url]
placeholderImage:placeholderImage
success:nil
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
safeSelf.image = [UIImage imageNamed:[NSString stringWithFormat:@"placeholderpic_%@_missing.png", NSLocalizedString(@"LanguageCode" , @"")]];
}
];
}else{
self.image = [self missingImage];
}
}
現在,有沒有辦法在設置后檢查imageView
url
。 比如, NSLog(@"%@", self.imageView.usingURL)
。 我想使用條件檢查它是否與另一個url
相同。 像這樣的東西:
if(self.imageView.usingURL == [NSURL URLWithString:[trip.destination getHeaderImageUrl]])
使用此類別在 UIImageView 中添加屬性
@interface UIImageView (URLImageView)
@property NSURL* usingURL;
@end
@implementation UIImageView (URLImageView)]
@end
現在,當圖像下載並設置為圖像視圖時,將 url 分配給圖像視圖,例如
self.imageView.usingURL = yourURL
現在您可以訪問此網址進行比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.