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
51
votes
7 answers

Animate UIButton state change

I'm using a UIButton with images for normal and highlighted states. They work as expected but I want to have some fading/merging transition and not just a sudden swap. How can I do that?
Johnny Everson
  • 8,343
  • 7
  • 39
  • 75
51
votes
2 answers

Selector syntax for swift 3.0

I am trying to add target into button this way: btnAll.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside) But it is giving me an error: Use of unresolved identifier 'buttonTapped' But I declared function like: func…
Ram Mani
  • 1,009
  • 1
  • 10
  • 15
50
votes
8 answers

Best radio-button implementation for IOS

I would like to ask if there are examples out there on how to implement radio-button options on an iPhone app. I find the Picker View quite big for a simple selection feature. I'm not sure if Apple excluded radio buttons on purpose, and whether if…
Jonas Arcangel
  • 2,085
  • 11
  • 55
  • 85
50
votes
4 answers

How to add fixed button to the bottom right of page

I'm having some trouble adding a fixed button on the bottom of my webpage. Been testing out different numbers with the pixels, but the button hasn't been showing underneath the page on the right. HTML
Brian Lam
  • 811
  • 3
  • 9
  • 10
50
votes
24 answers

Button in UITableViewCell not responding under ios 7

I have one tableview and each cell contains one button. It's working pretty well all iOS versions but 7. I don't know what's going on. The cell is constructed in one xib file. Could anyone give me some suggestions? Thanks in advance.
Xavier
  • 517
  • 1
  • 4
  • 5
49
votes
9 answers

storyboard positioning text below image inside a button

I am able to set the image and text for button. But it is aligned horizontally. I want the image and text to be aligned vertically inside the button. i.e., text below the image How to make these changes using storyboard? What I want is this: What I…
Ahalya Hegde
  • 1,571
  • 2
  • 18
  • 41
46
votes
7 answers

Add subview to UIButton

I'm trying to add subviews to a UIButton. This is working fine right now. But the button isn't clickable anymore as soon as I add the subviews. I use the following code: UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame…
Jos
  • 2,421
  • 5
  • 26
  • 30
46
votes
5 answers

ScrollView not scrolling when dragging on buttons

I have a scroll view that used to scroll when it didn't have buttons all over it. Now it does, and when dragging the mouse (on simulator) nothing happens (i think because the buttons are being pushed). How can I make this right?
DanielaM
  • 591
  • 1
  • 5
  • 6
46
votes
18 answers

Why is my "touch up inside" event for my UIButton not being called?

I've made plenty of buttons and I can't figure out why this one won't work. My hierarchy is set up like this: View -> Scroll View -> Subview -> Button There's a lot of other items in this subview and every one of them works when touched. In the…
Architekt
  • 2,141
  • 1
  • 22
  • 27
46
votes
11 answers

Use table view disclosure indicator style for uibutton ios

I have a custom view and i want to imitate the disclosure indicator found in table view cells. Is this possible ? Is there anyway of extracting that image ?
VBK
  • 1,435
  • 1
  • 15
  • 34
45
votes
7 answers

iOS - Delayed "Touch Down" event for UIButton in UITableViewCell

I have a custom UITableViewCell, which is initialized by the following: - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if…
Birrel
  • 4,754
  • 6
  • 38
  • 74
44
votes
10 answers

Round Top Corners of a UIButton in Swift

I know I can round all four corners using: myBtn.layer.cornerRadius = 8 myBtn.layer.masksToBounds = true Since I only want to round two, I did some research and found this: extension UIView { func roundCorners(corners:UIRectCorner, radius:…
Dave G
  • 12,042
  • 7
  • 57
  • 83
44
votes
2 answers

Trouble left-aligning UIButton title (iOS/Swift)

I'm having a problem left-aligning a UIButton's text. I also tried changing it to .Right but it still stays centered. I also tried aButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0) instead of…
stumped
  • 3,235
  • 7
  • 43
  • 76
44
votes
4 answers

How to set the alpha of an UIImage in SWIFT programmatically?

I found a lot solutions here but not for Swift, and I know you can do this with a UIImageView, but in my case i need an programmatically set alpha transparent background image for an UIButton. Best would be an UIImage extension! let img =…
Peter Kreinz
  • 7,979
  • 1
  • 64
  • 49
44
votes
24 answers

UIButton title text is not updated even if I update it in Main thread

I'm trying to change the title of an UIButton I've created programmatically, when the user clicks in it. So, this is my code to create the UIButton: myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width,…
neutrino
  • 2,297
  • 4
  • 20
  • 28