How to make custom buttons in iOS?

The iOS user interface is nice by default, but if I wanted to use images for buttons, how would I do it - is it OpenGL?

+7
source share
7 answers

Make the button a "custom button" type in the interface builder. Then set the background image to what you want the background to be.

Unfortunately, the default button style is a little boring. You will need to find or make a button with an image editor.

+11
source

UIButton supports many custom buttons. In nib (or storyboards or something else), just click the button and set "Type" to "Custom" in the attribute inspector on the right side of the screen. Then, just below this, set the “Status Configuration” parameter to the value you want (default, selected, etc.) to configure, and set the “Image” attribute to the desired image.

This image must be part of the project before it appears in the Image attribute (or in the application). You can add an image to the project by simply dragging it into the file navigator on the left side of the screen.

+11
source

You can use images for buttons using a few simple lines of code:

// code to set image for button at normal state [myButton setImage:[UIImage imageNamed:@"buttonImage.png"] forState: UIControlStateNormal]; 

You can also use Xcode to change the type to Custom, then you can set the images for each Status button.

You can learn more about UIButton states here.

+8
source

You can simply use the created PNG files. The UIButton class allows you to use custom images for all application states.

You really don't need to do individual rendering yourself, but if you really want to, you can use UIKit to draw the images themselves in code (without OpenGL): http://developer.apple.com/library/ios/#documentation/2ddrawing /conceptual/drawingprintingios/graphicsdrawingoverview/graphicsdrawingoverview.html

+6
source

You can do this by setting the properties of the image or backgroundImage in a UIButton . If you want your button to look beautiful when resized, you can use the stretchableImageWithLeftCapWidth:topCapHeight: UIImage with the corresponding image.

You can also use a custom component if it meets your needs.

+1
source

its very easy

enter image description here

change this two things. Change the “type” of the round rectangle to a custom rectangle and drag the image into the project and select it as the background. Run and go

0
source

Well, while I was looking too much for using custom buttons and graphics, I went through this site, they have a terrific tutorial that helped me a lot. I watched all the video tutorials and read several books, but nothing helped me, but this site and their 4 books are quite amazing and very useful for reading and understanding it.

http://www.raywenderlich.com/27191/learn-to-code-ios-apps-4-making-it-beautiful

0
source

All Articles