xiang
xiang

Reputation: 251

How to create UIBarButtoneItem with custom view but mimic the UIBarButtoneItem initwithimage behavior

I need to add badges and red dot to a UIBarButtonItem, since the frame is difficult to get(it's not a view), so I want to use a UIBarButtonItem with custom view. Currently the UIBarbuttonItem is init with method initwithimage, and I like the default behaviour as described in Apple documentation:

The images displayed on the bar are derived from this image. If this image is too large to fit on the bar, it is scaled to fit. Typically, the size of a toolbar and navigation bar image is 20 x 20 points. The alpha values in the source image are used to create the images—opaque values are ignored.

So, my questions is how to implement the above logic using custom view. That is, how to parse the image, replace the alpha value with tint color value?

Or go to another route, is there a safe and reliable way to get the position/frame of UIBarButtonItem relative to the UIToolbar or UINavigationBar?

Thanks in advance.

Upvotes: 0

Views: 110

Answers (1)

HackingOtter
HackingOtter

Reputation: 134

dUse - (id)initWithCustomView:(UIView *)customView and use a view containing the image and the badge as customView.

For the tint color you should take a look at this article: http://robots.thoughtbot.com/designing-for-ios-blending-modes

Upvotes: 1

Related Questions