开发者

How to highlight icons like the iOS toolbar

I would like to create som开发者_如何学Goe custom toolbars using some of the images I also use for the iOS Tab Bar. How do I highlight icons like Apple does on the Tab Bar?


Note that I haven't personally done this, but it is what I would do had I the need and time.

The UIToolBar seems to achieve the effect using 3 layers:

  1. bottom most layer is the rounded rectangle with black-gray shading
  2. second layer is the blue hilight gradient
  3. the topmost layer is the user supplied image, of which only the alpha channel is used.

The bottom and second layer can both be pre-rendered images made to suit arbitrary dimensions using [UIImage stretchableImageWithLeftCapWidth::].

To apply the topmost layer's alpha channel to the second layer, draw the topmost layer on to the second layer's image using UIContextDrawImage with blend mode of kCGBlendModeSourceIn. Then composite the result on top of the bottom most layer image and you should have something like what UIToolBar renders.


Have a look at the UIButton reference you will probably want to create an instance and then use;

- (void)setImage:(UIImage *)image forState:(UIControlState)state

Where you have UIControlState with these possible values;

  • UIControlStateNormal
  • UIControlStateHighlighted
  • UIControlStateDisabled
  • UIControlStateSelected
  • UIControlStateApplication
  • UIControlStateReserved

There is also the property showsTouchWhenHighlighted which by default is NO but will provide a glow around a button when tapped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜