-2

I want to use the UIAlertView Button style outside of the UIAlertView in my View Controller. Again, to be clear, I don't want the button inside the UIAlertView, I just want the button style in my own View Controller.

Does the iOS SDK provide this functionality out of the box, or would I have to make my own custom button to replicate the one of UIAlertView?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
TheNotSoWise
  • 869
  • 2
  • 10
  • 15
  • You'd likely need to replicate it yourself with a UIButton, but out of curiosity, what aspect of the UIAlertView button are you trying to replicate? It seems to be a simple white button with blue text, either bolded or unbolded, at least for a normal UIAlertView. – Nerrolken Apr 16 '15 at 18:02
  • @Nerrolken The button has padding around the center text and changes background to a light grey when it's tapped. – TheNotSoWise Apr 16 '15 at 18:04
  • 1
    And you don't know how to make a button that does that? – matt Apr 16 '15 at 18:14

1 Answers1

0

The two things you're looking for can be easily achieved in Interface Builder, without even needing to subclass UIButton. They're simply settings within the UIButton class.

Button Size/Padding

  • To change the padding around the text of a button, the easiest way is simply to change the size of the button. You can do this programmatically, by altering the button's frame, or in Interface Builder by simply dragging the edges of the button to the appropriate size.
  • Alternatively, you can alter the font size of the button's label, again either programmatically or in IB, to give more room within a button of a given size. Also check out the "Line Break" property, which determines how the button handles text that is too long to display.

Selected Color

  • A UIButton has several "states," such as Normal, Selected, Highlighted, and Disabled. In each of these states, you can set the button's title, font, text color, background image, etc. What you're looking to do is set the button's background color to white for the Normal state, and gray for the Highlighted state, which unfortunately isn't possible, but there are plenty of SO answers about how to achieve the same effect.
  • Alternatively, you can set background images by a button's state, so you can set a pure-white background image for the Normal state and a gray background image for the Highlighted state.
Community
  • 1
  • 1
Nerrolken
  • 1,975
  • 3
  • 24
  • 53