I am using UITabBar
and UITabBarItem
. I have an URL of an image
. I set UITabBarItem's image to that image using URL. But image is not showing up. If I use any other image from my MacBook, it works. My URL is correct, which I verified by copy pasting in browser.
Below is my code. Can anyone see any problem?
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];
I use below method to resize the image to fit in UITabBarItem // resizes given image to specified 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;
}