UIBarButtonItem clone
I have an UIButton subclass and I need its look to be identical to an UIBarButtonItem when placed on the classic blue tinted navigation bar.
The UIBarButtonItem has a border with a kind-of gradient, being darker at the top and blue-ish at the bottom, which I 开发者_C百科suspect it's done with some alpha trick. The bottom looks recessed too.
There's also some overlay which makes the button a little bit darker and even more when in the selected state.
Can anyone help?
The short answer is that you are going to have to spend some time learning how to draw gradients and shadows in Core Graphics.
The relevant documentation is called "Quartz 2D Programming Guide".
After you learn how to draw shadows and gradients, you are going to have to spend quite a bit of time zoomed in comparing what you are drawing vs what the button looks like.
You didn't ask, but this is what I would do:
Subclass UIBarButtonItem and add your custom functionality in there. Let UIBarButtonItem draw itself.
It might be easier for you just to use a photoshopped image. Use the image for your button. This way you don't have to worry about custom drawing code.
You can use Three20 library,
specially have a look at sample TTCatalog app.
Look at the source file "StyleTestController.m"
https://github.com/facebook/three20/blob/master/samples/TTCatalog/Classes/StyleTestController.m
I'm sure you'll find your answer here.
Cheers,
精彩评论