6

I would like to be able to use a custom view as a UITabBarItem. I can't seem to find any information about this.

I'd like my tab items to be little circular UIViews containing an image. Is this possible? Is there maybe an open source library that lets me do this?

James Harpe
  • 4,315
  • 8
  • 47
  • 74
  • That's ridiculous. "I would like to be able to use a custom view as a UITabBarItem." This sentence clearly implies that I want to replace the default uitabbaritem with an arbitrary view, so obviously I don't want elements of the default view to remain. What could possibly be inappropriate about gently pointing this out in a comment? I haven't tried anything because it's not immediately clear to me how it would be possible, and I can't find any other questions addressing this particular issue. – James Harpe Dec 12 '13 at 02:36

1 Answers1

0

You could create a UIImage from a UIView and then use that image to create your tabbar item. Here's how I'd do it.

First, create the UIImage (assuming you already have the UIView):

// Remember to import Quartz!
UIView *view = INITIALIZE_YOUR_VIEW;
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

Then you can use the image to create the tabbar item:

UITabBarItem *tabItem = [[UITabBarItem alloc] initWithTitle:@"Title" image:image tag:1010];

And that's it.

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42