Designing Buttons in iOS 5

Designing Buttons in iOS 5

By default Apple provides well styled interface elements to use when designing your application. Except for the UIButtons. To me using any other stock element is fine, but nothing screams amateur design like a default UIButton.

In my iOS apps I’ve tried a couple different methods of styling these buttons to get a more desirable look. While I know you can design buttons entirely in code, my Photoshop skills greatly exceed my programming skills. So my buttons are all designed in Photoshop, then imported as PNG files. Also iOS does such a good job with PNG optimization that I see it as the best choice.

Option 1: Using an Exactly Sized Image

 UIImage *buttonImage = [UIImage imageNamed:@"orangeButton.png"];
 UIImage *buttonImageHighlight = [UIImage imageNamed:@"orangeButtonHighlight.png"];
 // Set the background for any states you plan to use
 [saveButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
 [saveButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];

You can also do this in Interface Builder by setting the button Type to “Custom” and then add the image name to the background property.

 

Option 2: Using resizableImageWithCapInsets (iOS 5 Only)

This is my current preferred method (in most cases). It allows me to use the same images for most of the buttons across an application.

 UIImage *buttonImage = [[UIImage imageNamed:@"orangeButton.png"]
 resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
 UIImage *buttonImageHighlight = [[UIImage imageNamed:@"orangeButtonHighlight.png"]
 resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
 // Set the background for any states you plan to use
 [saveButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
 [saveButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];

Pretty straightforward. Here you can change the button dimensions without having to create a new image. In Interface Builder (or with code) you will need to set the titleLabel color as well as the shadow position and color.

Final Tips:

  • Leave the text out of your images. This will scale better for the retina display and allow you to change it dynamically. No one wants to have to open Photoshop just to tweak some button text.
  • Always include @2x versions of each image.
  • If you prefer most of the customization (color, background, shadow) can be done in Interface Builder. Writing it in code is only required if you are using the second method (resizableImageWithCapInsets).

Whichever method you prefer, you can use some of my sample button styles to get started. Both methods still seem rough, so I would appreciate feedback and ways to better create buttons.

Download All the Button Files

Signup for my iOS Design Newsletter for more app design tips and articles.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值