Friday, May 21, 2010

Gradient Buttons Yet Again

I added two more button styles to the iPhone Gradient Buttons project and made stroke color and stroke weight configurable options. The two new styles look exactly like the old Black and White style, only the highlight state is a blue gradient. These simulate the style used in alert sheets in several Apple applications.

Screen shot 2010-05-21 at 4.29.17 PM.png

Some of the Core Graphics code was machine-generated and is in kind of rough shape, but it works. I'm thinking about refactoring the different styles methods into something shorter, perhaps a plist, or just C arrays with the different numeric values.

For some strange reason, when I try to use arrayWithObjects: instead of creating a mutable array and manually adding the colors one at a time, I get a NULL gradient back. I have no idea why, but it's working this way at least.

Anyone who wants to contribute, let me know, I'd be happy to add committers.



24 comments:

lovemeister said...

The buttons look great. Can you make the button style as used by the UICatalog sample app's Buttons? You know, the ones with the fat border on the outside. It'd be nice to have red, green, blue, black, white, and gray ones of those too.

Josh said...

Adding committers to a Google Code project is so 2001. Put it up on github.

Adam Alexander said...

These buttons look great! Thanks so much for releasing them.

an0 said...

Hi, Jeff,

The buttons like very nice. Thanks for sharing.

However, I've some questions about the code.

1. What's the "resolution" for?

I don't quite understand your definition:
CGFloat resolution = 0.5 * (self.bounds.size.width / imageBounds.size.width + self.bounds.size.height / imageBounds.size.height);

Do you use it as the scale of (bounds + strokeWidth) / bounds?

2. The code of drawRect: is not adaptive to other strokeWeight. You can try a strokeWeight of 2.0 to see the effect.

If I get the intended usage of "resolution" right, I think I've written a simpler, cleaner and more adaptive version of drawRect: based on your code. And I'd like to be contributor:)

Ben said...

thanks again for sharing. one question: how would you go about creating one of these buttons programmatically, instead of through Interface Builder?

My store said...

They are your New Balance for sale , so here at New Balance Altoona we know new balance 580 for sale that each athlete has different needs, new balance 574 and different feet. We strive to new balance 996 provide the right shoe and a perfect fit for new balance 993 every customer. All athletes understand the new balance 1500 connection between superior new balance 1300 performance and well-fitted shoes - new balance 1400 that's why we carry New Balance 576 sneakers and footwear in a wide new balance 577 variety of sizes and widths so that we can provide the new balance 999 best fit for the best price.

My store said...

These shoes made my trip to onitsuka tiger mexico 66 yellow black Argentina that much more enjoyable. I needed a pair of onitsuka tiger mexico 66 by asics shoes that I could walk great mens onitsuka tiger mexico 66 distances in and stand in for asics onitsuka tiger mexico 66 several hours at a time. These were my answer. They have great support, and give the feeling asics tiger mexico 66 that one is walking on air. They did get dirty, when we went rappelling. onitsuka tiger mini clubman Although you are not supposed to, I washed them on gently cycle in my front loader onituka tiger mini cooper washing machine. No harm, no foul. I highly recommend them.

My store said...

Introduced in 1966, Onitsuka Tiger Mexico 66 were the first shoes with the famous Tiger Stripes. ASICS GEL-KINSEI 2 were worn at the Mexico Olympic Games in 1968. With lace up asics gel kinsei 2 sale front and tracks in asics gel kinsei 2 mens the side and suede asics kinsei 2 for sale effect trim on front and back. Purchase Asics Onitsuka Tiger mini cooper and receive onitsuka tiger mini clubman Learn about running shoe types such as motion control, onitsuka tiger mid runner performance training and stability onitsuka tiger mexico 66 mens shoes and discover which type authentic onitsuka tiger shoes sale best fits your pronation type.The original Kinsei was asics gel stratus mens shoes classified by Asics as a asics gel stratus 2.1 for mens Stability+ shoe. The Kinsei II is asics gel stratus 2.1 sale Neutral+ shoe. If you look at the Asics Shoe Fit Chart

My store said...

The best home based alife shoes sale business to start is one that alife sneakers sale new york gives you the ability to alife sneakers for sale leverage your time. Basically, you want a cheap alife sneakers business that continues to operate alife sneakers and earn income for you even while you’re not working. cheap alife shoes sale This is key if you want to spend more time with alife everybody hi your family. Businesses that lack alife everybody low this feature end up owning you, alife shoes online sale and you’ll most likely have less free time than you did as a 9 to 5 employee.

My store said...

Introduced in 1966, Onitsuka Tiger Mexico 66 were the first shoes with the famous Tiger Stripes. ASICS GEL-KINSEI 2 were worn at the Mexico Olympic Games in 1968. With lace up asics gel kinsei 2 sale front and tracks in asics gel kinsei 2 mens the side and suede asics kinsei 2 for sale effect trim on front and back. Purchase Asics Onitsuka Tiger mini cooper and receive onitsuka tiger mini clubman Learn about running shoe types such as motion control, onitsuka tiger mid runner performance training and stability onitsuka tiger mexico 66 mens shoes and discover which type authentic onitsuka tiger shoes sale best fits your pronation type.The original Kinsei was asics gel stratus mens shoes classified by Asics as a asics gel stratus 2.1 for mens Stability+ shoe. The Kinsei II is asics gel stratus 2.1 sale Neutral+ shoe. If you look at the Asics Shoe Fit Chart

airshoes said...

I like your blog. Thank you. They are really great .
Some new style Puma Cat shoes is in fashion this year.
The Nike Air Shoes is a best Air Shoes .
Red Shox is good and Cheap Nike Shoes.
If you are a fans of Puma basket,we would offer the good and Cheap Puma Shoes for you .the nike shox torchis best christmas gift now.
Running Shoes
Nike Shox R4
Nike Air Force Ones
The information age is really convenient .

Timos said...

Hi Jeff,

First of all thanks a bunch for this - it comes at a great time with iOS4 on the way with various resolutions. I found your code to work great in the simulator - but for some reason the red and green button did not work on my 3G. If found the following bugs:

When you go to add the colors for the highlighted state you add the last color to the colors array (not the colors2) and then you set the highlighted state to the colors array:

[colors addObject:(id)[color CGColor]];
self.highlightGradientColors = colors;

When I changed to:

[colors2 addObject:(id)[color CGColor]];
self.highlightGradientColors = colors2;

The buttons showed up fine on the device. Not sure how it worked in the simulator - very strange...

Kirby said...

Hi Jeff,

I encountered the same issue reported by Timos. Green and Red buttons created programmatically were not displaying properly. One caused was the extra color added to the colors array on line 148 and 391. Another thing I noticed in green and red is that colors2 array is created but not used. Not sure if you intended to do that on purpose or if it is a bug.

Other than that, the code works great for me. Thanks for providing it!!

ratbastid said...

I had the same problem as Timos... but only after upgrading my 3G to iOS4. Prior to that this impossible array assignment worked flawlessly. Weird!

Cole said...

Has anyone had any luck trying to make these buttons look more UIBarButton'ish? With more of a flat/sharp/harder gradient? Thanks!

King Bayern Munich said...

Wow, this is too cool. I am very like it, Thank you for sharing, let me so happy! At the same time ,i feel Forged Steel Valve

King Bayern Munich said...

Oh, so unexpected, so surprise! Very touching, so well written and I have some perception, learning very much. Thank you for sharing. Very happy to see these and believe that your point of view. This same time,i love floating ball valve

King Bayern Munich said...

Cool. Talking about makes sense. Is recognized. Hope that it will often share such a good text. I will always be concerned about, because you can learn some knowledge, thank you for sharing, and i love lug butterfly valve

SteveK said...

Thanks for posting this. It is an enormous help. I have to create a Yellow version of the button and I want the same beveled look that you were able to create in your buttons. Is there a formula for the two sets of four colors, one set for a up button and one set for a depressed button, that creates that look. I have been trying to play around with the ratios from your example without much luck. How do I calculate for colors around a single color to get that look? Thanks again for posting.

SEO Services Consultants said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Web Design Company

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels

p90xexercise said...

Great update Jeff, keep up the good work.

Devin said...

Very well explained the gradient buttons.
generic viagra
Thanks for sharing this info.

Hizon said...

This is what I love in iPhone. It updates for better cellphone experience. I hope someday they can make not just a phone. =)

Sasha of skin tag removal