Questions tagged [uibutton]

UIButton is a subclass of UIView for displaying buttons in iOS. It implements the target action paradigm to send events to the controller layer.

A UIButton intercepts touch events and sends an action message to a target object when tapped. Methods for setting the target and action are inherited from UIControl (). This class provides methods for setting the title, image, and other appearance properties of a UIButton. By using these accessors, you can specify a different appearance for each button state:

  • UIControlStateNormal,
  • UIControlStateHighlighted,
  • UIControlStateDisabled,
  • UIControlStateSelected.
  • UIControlStateFocused.

Resources:

11252 questions
89
votes
9 answers

UIButton Long Press Event

I want to emulate a long a press button, how can I do this? I think a timer is needed. I see UILongPressGestureRecognizer but how can I utilize this type?
Andrea
  • 1,597
  • 3
  • 18
  • 24
87
votes
8 answers

Change UIButton BorderColor in Storyboard

I Set CornerRadius and BorderWidth for UIbutton in User Defined Runtime Attributes. Without adding layer.borderColor it works Well and Display border in black color. But when add layer.borderColor does not work(does not show border).
Mohamed Jaleel Nazir
  • 5,776
  • 3
  • 34
  • 48
87
votes
4 answers

How can I init a UIButton subclass?

I tried to add a double value to a subclass of UIButton in Swift. I tried all kind of inits and get and set options, but I couldn’t get it to work. So I started with this: class CVSTButton : UIButton { var cvstPosition: Double required…
Alexander Schutte
  • 871
  • 1
  • 7
  • 3
86
votes
17 answers

How to add 2 buttons into the UINavigationbar on the right side without IB?

How can I add 2 buttons into the UINavigationBar without XIB? The 2 buttons should be aligned on the right side of the UINavigationBar. I know how I can add one button, but how about two?
Alexander
  • 1,121
  • 2
  • 10
  • 6
82
votes
17 answers

Setting up buttons in SKScene

I'm discovering that UIButtons don't work very well with SKScene, So I'm attempting to subclass SKNode to make a button in SpriteKit. The way I would like it to work is that if I initialize a button in SKScene and enable touch events, then the…
AlexHeuman
  • 1,006
  • 1
  • 10
  • 14
81
votes
21 answers

How do I scale a UIButton's imageView?

I created a UIButton instance named "button" with an image using [UIButton setImage:forState:]. The button.frame is larger than the image's size. Now I want to scale this button's image smaller. I tried changing button.imageView.frame,…
vcLwei
  • 1,927
  • 3
  • 16
  • 13
79
votes
5 answers

How to add a drop shadow to a UIButton?

I would like to add a drop shadow to a UIButton. I tried to use self.layer.shadow* properties. Those properties work in UIView, but they behave differently in UIButton. I would really appreciate it if I could get any pointers to draw the drop…
Chris Frost
  • 1,069
  • 2
  • 10
  • 7
79
votes
27 answers

Left-align image and center text on UIButton

I've seen posts regarding right alignment but I can't get left-alignment to work. I want the button to take up the width of the screen, with the image on the left and the title/text in the center. This does not work (at least reliably): …
user1007721
  • 811
  • 1
  • 6
  • 4
78
votes
11 answers

Create a button programmatically and set a background image

When I try creating a button and setting a background image in Swift: let button = UIButton.buttonWithType(UIButtonType.System) as UIButton button.frame = CGRectMake(100, 100, 100, 100) button.setImage(IMAGE, forState:…
Gary
  • 1,020
  • 1
  • 8
  • 20
77
votes
2 answers

UIButton events. What's the difference?

I've encountered a problem where my button should remain "pressed down" while it shows popover called from it. Popover is selector for some filter and filter is shown on button itself. When I tap on it and it shows popover it becomes deselected no…
Protheus
  • 3,068
  • 4
  • 17
  • 25
76
votes
8 answers

iOS 7 round framed button

the iOS App Store has a blue round framed button for buying/downloading apps. In my App you can download additional content and I want to have a similar button, just because it looks familiar to the user. If you don't know, what I mean: these…
h345k34cr
  • 3,310
  • 5
  • 21
  • 28
75
votes
15 answers

UIBarButtonItem with custom view not properly aligned on iOS 7 when used as left or right navigation bar items

The following code works up through iOS 6: UIButton *myButton = nil; myButton = [UIButton buttonWithType:UIButtonTypeCustom]; myButton.bounds = CGRectMake(0,0,44,30); // setup myButton's images, etc. UIBarButtonItem *item = nil; item =…
74
votes
10 answers

UIButton Text Margin / Padding

I have the following layout, and I'm trying to add a padding to the left and right.. The controls are a disabled UIButton. My code for creating a button is this: UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(90, 10, 50, 20)];…
PartySoft
  • 2,749
  • 7
  • 39
  • 55
74
votes
6 answers

How can you rotate text for UIButton and UILabel in Swift?

How can you rotate text for UIButton and UILabel? 90 degrees, 180 degrees. Note: Before you mark this as a duplicate, I am intentionally modelling my question as a Swift version of this one: How can you rotate text for UIButton and UILabel in…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
73
votes
11 answers

How to achieve UIButton / UILabel 'padding' in iPhone app

I've got various views in my iPhone application that require padding e.g a custom UIButton with text aligned left, and a UILabel with a background color. This may be a really stupid question, but how can I apply 'padding' to move the text off the…
user210437