Traversing the road to success.

Tired of the default iOS buttons? Yes, we too. Don’t want to spend hours of graphical design just to put a new button style? Nah, we neither.

About a year ago, Erica Sadun posted how to use the undocumented UIGlassButtons from iOS to generate a shinny button, and then copy it to be used as an image in your real buttons. The post is still accessible here:

But, what if you could avoid the pain of generating each button also and just select the color of the button on your code? We thought it wouldn’t be too hard to do it, and Juani (our star programmer) did it.

I just compiled his code in a project that will demonstrate how to use these buttons. The CrystalButton class is just a subclass of UIButton so all you have to do is use them like normal buttons (even in the Interface Builder) but be aware that now you have a new property to set: the tint color of the button.

@property (nonatomic, retain) UIColor * tintColor;

Without further delay, here is the CrystalButton sample:

Play with it. Enjoy it. Tell us what you think.

– Rula.

Comments on: "How to build Glass Buttons in iPhone programmatically" (1)

  1. David A Knight said:

    Nice code, one small problem in dealloc though. Setting self.tintColor = nil; causes a crash when the button is disposed due to setGradient being called and trying to setup colors and locations on the layers that have just been released.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Tag Cloud

%d bloggers like this: