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
31
votes
4 answers

How to Change textLabel property in UIButton programmatically in iOS?

I have a UIButton that should have 2 statuses - "Play" and "Pause"; i.e. - at the first time the user sees it it says "Play" and then whenever the user clicks it it should switch between "Play" and "Pause". I managed to create the controller itself…
Ohad Regev
  • 5,641
  • 12
  • 60
  • 84
30
votes
11 answers

How do you change UIButton image alpha on disabled state?

I have a UIButton with an image and on its disabled state, this image should have .3 alpha. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *arrowImage = [UIImage imageNamed:@"arrow.png"]; [button setImage:arrowImage…
pixelfreak
  • 17,714
  • 12
  • 90
  • 109
30
votes
3 answers

How set background color of a button - xcode

How can I set the background color of a UIButton in Xcode? I see the property Background and Image in the layout property but i can't set anything in this two. (I can set only image in both not colors)
GMX
  • 950
  • 1
  • 14
  • 29
30
votes
18 answers

Align button image to right edge of UIButton

There are plenty of threads about aligning a button image according to the title text, but I can't find anything about just aligning the image to the right side of the button. This has no effect: button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0,…
soleil
  • 12,133
  • 33
  • 112
  • 183
30
votes
2 answers

set UIButton's buttonType programmatically

I have a UIButton which I've added in IB, however the view behind this button changes color and I need to switch the button's type between InfoDark and InfoLight. Bizarrely though, buttonType property is read only. So how can i switch between light…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
30
votes
4 answers

Swift - UIButton overriding setSelected

I'm making a UIButton subclass in Swift to perform custom drawing and animation on selection What would be the equivalent in Swift of overriding - (void)setSelected:(BOOL)selected in ObjC? I tried override var selected: Bool so I could implement…
LorTush
  • 719
  • 1
  • 8
  • 14
30
votes
1 answer

iPhone Dev - Create UIButton Manually

I'm learning how to develop on the iPhone, I bought a book called Beginning iPhone 3 development Exploring the SDK. After I bit I decided to ditch Interface Builder. I still design all my views in IB, but I write It all in code and only use the nib…
mk12
  • 25,873
  • 32
  • 98
  • 137
29
votes
6 answers

iOS UIButton with UITextAlignmentLeft still centering text?

Problem: After setting a button's titleEdgeInset and UITextAlignmentLeft the button's title is still centered, not left-aligned. Details: I have a button 200px wide using a custom background with an image on the left. Since I don't want the button…
memmons
  • 40,222
  • 21
  • 149
  • 183
29
votes
7 answers

How to open iPhone's default browser?

I placed a Facebook button in my iPhone app. How to open the iPhone's default browser when clicking on that button and loads the Facebook login page?
Arun
  • 3,478
  • 8
  • 33
  • 46
29
votes
18 answers

UIButton not responding used in a custom UITableViewCell

I know this issue is already been asked few times in SO. Despite trying those out, I am still unable to solve my problem. I am using a UITableView inside a UIViewController. I have a custom UITableViewCell which has couple of buttons in it.…
user2695433
  • 2,013
  • 4
  • 25
  • 44
29
votes
13 answers

Swift add badge to navigation barButtonItem and UIButton

I am trying to display badge on my notification button, in app as displayed on AppIcon. So far whatever i have researched is related to Obj. C, but nothing that specifically discussed way to implement that solution into Swift, Please help to find…
coolagrwal
  • 293
  • 1
  • 4
  • 7
29
votes
2 answers

CALayer - Place sublayer below storyboard UIButtons?

I've got a view controller in my storyboard with several UIButtons. One of them activates an AVFoundation camera preview layer shown in a sublayer: captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc]…
golmschenk
  • 11,736
  • 20
  • 78
  • 137
29
votes
3 answers

Animate UIButton's title change

Here I found how to animate UIButton's title change using now-deprecated beginAnimations:context: method: UIBUtton title animation for iPhone How to do the same thing using current APIs? Update: I've tried to use block-based…
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
28
votes
6 answers

How to center an image inside an UIButton without stretching in both direction in Swift?

I am making a custom keyboard and I need to centre the image of the shift icon inside the shift button. The image is 100px x 100px. However, the button frame in portrait is 36pt x 38pt, and in landscape, it is 68pt x 32pt. I have tried using button…
Ariel
  • 2,471
  • 1
  • 26
  • 43
28
votes
3 answers

UIButton height is 0 but title is still visible

I have an UIButton placed with constraints. In the interface of the view controller I created an IBOutlet for the height constraint of the button. In viewDidLoad method I have the code: myButtonConstraint.constat = 0; [self.view layoutIfNeeded]; In…
Andrei Marcu
  • 588
  • 6
  • 9