How to make custom buttons in iOS?

后端 未结 7 1506
野的像风
野的像风 2021-02-06 09:01

The default iOS UI is nice but if I wanted to use images for buttons instead how would I do that - is it OpenGL?

相关标签:
7条回答
  • 2021-02-06 09:52

    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 images for each button "state."

    You can read more about UIButton states here

    0 讨论(0)
  • 2021-02-06 09:57

    UIButton has a lot of support for custom buttons. In the nib (or storyboard or whatever), just click on the button and set its "Type" to "Custom" in the attribute inspector on the right side of the screen. Then, just below that, set the State Config to the sate you'd like (default, selected, etc) to customize, and set Image attribute to the image you'd like.

    That image must be part of the project first before it will show up in the Image attribute (or in the app). You can add the image to the project simply by dragging it into the file navigator on the left side of the screen.

    0 讨论(0)
  • 2021-02-06 09:59

    Well so far i was too looking for using custom buttons and the graphics, I've come through this site they have some awesome tutorial which was quite helpful for me. I've watched all the video tutorial and read some books but nothing helped me but this site and their 4 books are quite awesome and really helpful to read and understand it well.

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

    0 讨论(0)
  • 2021-02-06 10:02

    You can simply use PNG files that you create yourself. The UIButton class allows you to use custom images for all the different states of the application.

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

    0 讨论(0)
  • 2021-02-06 10:04

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

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

    0 讨论(0)
  • 2021-02-06 10:05

    You can do it by setting image or backgroundImage properties of a UIButton. If you want your button to look nice when the size changes, you can use stretchableImageWithLeftCapWidth:topCapHeight: method of UIImage, with an appropriate image.

    You may also want to use a custom component if it satisfies your need.

    0 讨论(0)
提交回复
热议问题