问题
I'm trying to build an iPad app that uses custom images as buttons with my own custom behaviors when the buttons are selected, touched up inside, outside, etc.
I'm trying to use Interface Builder to do this, but I have a lot of questions as to what the various text fields mean such as Background Image, Shadow Color, Shadow Offset, Highlight Tint, Drawing, etc.
Does anyone know of a good tutorial that goes over UIBUttons on Interface Builder?
回答1:
Probably the best online custom button tutorial I've run into is at http://ios-blog.co.uk/iphone-development-tutorials/how-to-code-custom-ios-buttons/ . It explains how image stretching works, what the “caps” parameters are pretty well and in plain English. (Offline, among other things, I recommend the “Spiffing Up the Button” section (pg. 92) of Beginning iPhone 3 Development by Dave Mark and Jeff LaMarche – if you have the book, of course.) I haven't found the other online tutorials verbose enough – generally, they only present some code, but no image stretching explanation. Before running into the tutorial I've linked to, it took me quite a bit of experimenting to find out how images should be presented.
Some additional example code explaining the four different button states are at, among others, Set a button background image iPhone programmatically
回答2:
For starters the default background image scales according to content mode (Where the default image does not). There are 4 states you can set the background image for "Default, Highlighted, Selected, Disabled".
You can set a specific action for any of the touch events listed in the 6th tab under the inspector (right side on my set up Xcode 4) To do so just click and drag to the intended receiver. You do not need to ctrl-click or right click (It will not work from the inspector)
When you ctrl-click or right click and drag on the actual button in the hierarchy or layout view, by default it sets the target and action for Touch Up Inside
来源:https://stackoverflow.com/questions/8014497/interface-builder-tutorial-on-how-to-customize-uibuttons-in-xcode-4-2