と を使用UITabBar
してUITabBarItem
います。私は持っていURL of an image
ます。URL を使用して UITabBarItem の画像をその画像に設定します。しかし、画像が表示されません。MacBook の他の画像を使用すると、機能します。私の URL は正しいです。ブラウザにコピーして貼り付けて確認しました。以下は私のコードです。誰でも問題を見ることができますか?
UIImage * iconImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:singleMatch.imageUrl]]];
// add UITabBarItem to an array
[tabs addObject:[[UITabBarItem alloc] initWithTitle:singleMatch.realName image:[self convertImage:iconImage toSize:CGSizeMake(40, 30)] tag:i]];
[self.chatTabBar setItems:tabs animated:YES];
以下のメソッドを使用して、UITabBarItem に収まるように画像のサイズを変更します // 指定された画像を指定された CGSize にサイズ変更します
- (UIImage *)convertImage:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizedImage;
}