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
44
votes
8 answers

UIButton title color change on highlight - How to turn it off?

I have created a button. The title's color is black by default. But when I press it, the color changes to be a little blue and never changes back again, how does this happen? Can anyone tell me why? And I want the button's title remain black all the…
NewXcoder
  • 705
  • 1
  • 5
  • 18
43
votes
9 answers

UIButton label text is being clipped

I have a UIButton built in Interface Builder that has a default label. In Xcode, I'm changing the label text dynamically like so: myButton.titleLabel.text = @"this is the new label"; However, when the text updates, the new string is being clipped…
thenameisnick
  • 613
  • 2
  • 10
  • 12
43
votes
12 answers

detecting uibutton pressed in tableview: Swift Best Practices

I have a tableview with a variable number of cells representing students that correspond to their particular instructor. They are custom cells with a button that triggers a segue to a new VC, bringing up detailed information on the student whose…
jamike
  • 443
  • 1
  • 4
  • 6
43
votes
7 answers

UIButton with IB_DESIGNABLE throws runtime attribute warning and does not render in Interface Builder

I'm running Xcode 6.1 and I have been using IB_DESIGNABLE with IBInspectable for quite a few projects already but all of the sudden it just doesn't work anymore. I have created subclassed buttons that arrange the image and the title vertically…
Lucas van Dongen
  • 9,328
  • 7
  • 39
  • 60
43
votes
8 answers

Hooking up UIButton to closure? (Swift, target-action)

I want to hook up a UIButton to a piece of code – from what I have found, the preferred method to do this in Swift is still to use the addTarget(target: AnyObject?, action: Selector, forControlEvents: UIControlEvents) function. This uses the…
rafalio
  • 3,928
  • 4
  • 30
  • 33
43
votes
11 answers

How to add only a TOP border on a UIButton?

I know how to add border to a button in iOS 7, with the following code : [[myButton layer] setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]]; [[myButton layer] setBorderWidth:1]; [[myButton layer] setCornerRadius:15]; But…
Jonathan F.
  • 2,357
  • 4
  • 26
  • 44
42
votes
13 answers

UIButton that resizes to fit its titleLabel

I have a UIButton that I add to my view controller's view in a storyboard. I add centering constraints to position it and leading space constraints to limit its width. In code I add: self.button.titleLabel.numberOfLines =…
Darren
  • 10,091
  • 18
  • 65
  • 108
41
votes
5 answers

UIButton of type UIButtonTypeCustom will not display Title (iPhone)

I must have overlooked something completely obvious?? but my button displays its image and size correctly, but I simply can't get the Title to show up. I did a really simple test, the Title does not even show up when I do this: CGRect frameBtn =…
RickiG
  • 11,380
  • 13
  • 81
  • 120
41
votes
5 answers

Change colour of dark grey highlight when holding down custom UIButton?

I have a custom UIButton which is a cloud, transparent black and white .png file, with no down state, just one image. When tapping and holding the finger over it, it turns dark grey. I'm trying to change that dark grey to something a little less…
Luke
  • 9,512
  • 15
  • 82
  • 146
40
votes
3 answers

UIButton setText programmatically

I have about 10 UIButtons on xib file and want to setText programmatically
user401383
  • 401
  • 1
  • 4
  • 5
40
votes
9 answers

Adjust font size of text to fit in UIButton

I want to make sure the button text fits into a UIButton, while the UIButton has a fixed size. Of course I can access the titleLabel of the UIButton. In a label I would set autoshrink to minimum font scale which seems to correspond to…
MarkHim
  • 5,686
  • 5
  • 32
  • 64
40
votes
8 answers

How to change the highlighted color of a UIButton?

I created a navigation button in my UINavigationController. I set it to be highlighted when touched: [someButton setShowsTouchWhenHighlighted:YES]; Is there a way to change the highlighted color to something other than the default white?
Code Monkey
  • 968
  • 1
  • 14
  • 26
40
votes
2 answers

UIButton title changes to default

I feel like this is probably a stupid question... but anyway I have this kind of weird UIButton title behavior. The button is set up and connected to both an action and a property in IB (the action is startButtonPushed and the property is…
Dustin
  • 6,783
  • 4
  • 36
  • 53
39
votes
17 answers

Multiline UIButton and autolayout

I have created a view controller that looks like this: I want the two top buttons to always have 20 points between themselves and the left/right edges of the whole view. They should always have the same width too. I have created the constraints for…
user3124010
38
votes
4 answers

Having trouble getting UIView sizeToFit to do anything meaningful

When I add a subview to a UIView, or when I resize an existing subview, I would expect [view sizeToFit] and [view sizeThatFits] to reflect that change. However, my experience is that sizeToFit does nothing, and sizeThatFits returns the same value…
FishesCycle
  • 1,011
  • 1
  • 10
  • 24