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
73
votes
12 answers

UIButton bottom shadow

I have a UIButton which is very similar to the standard iOS keyboard alphabet button. I am not sure how to create a shadow only for the bottom layer like how iOS have done. I use the below code, but I see a shadow on all the side, not just the…
Neelesh
  • 3,673
  • 8
  • 47
  • 78
73
votes
7 answers

How to add padding-left on a UIButton created programmatically?

I am having a trouble adding left padding on a UIButton. I have a UIButton with UIControlContentHorizontalAlignmentLeft. I want the text to be displayed on the left side but it is too left. when I give the border, it doesn't look good. I would like…
MissStack
  • 833
  • 1
  • 6
  • 6
71
votes
19 answers

Adding a closure as target to a UIButton

I have a generic control class which needs to set the completion of the button depending on the view controller.Due to that setLeftButtonActionWithClosure function needs to take as parameter a closure which should be set as action to an unbutton.How…
Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
70
votes
7 answers

How can you rotate text for UIButton and UILabel in Objective-C?

How can you rotate text for UIButton and UILabel? 90 degrees, 180 degrees.
jdl
  • 6,151
  • 19
  • 83
  • 132
69
votes
6 answers

How to initialize UIColor from RGB values properly?

I am working on an iPhone application which uses various colors. When user selects the particular color button I set drawing color accordingly. I am getting the color for some but in the most of the cases I am getting white color. Here is my…
slonkar
  • 4,055
  • 8
  • 39
  • 63
69
votes
10 answers

UIButton with both image and text possible?

I have a button of size width 200 and height 270. I want to have text and image on the same button. Not as a background image on that text. Instead of this, I want to display the text with height 120 and image of height 150 on the same button. How…
Viral Narshana
  • 1,855
  • 2
  • 21
  • 45
69
votes
6 answers

Minimum sensible button size on iPhone

I'm designing an iPhone app that features a rather large set of onscreen rounded rect buttons. Given finger-based touchscreen UI, what do you think would be the smallest sensible button size? I need to fit as many of them as I can in the viewport…
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
69
votes
7 answers

How to not stretch an image in UIButton

I'm trying to create a custom UITableViewCell programmatically and one of the subviews of this cell is going to be a button with an image in it (a simple image of a magnifying glass). However, I want the button's image to be centered and scaled…
Nosrettap
  • 10,940
  • 23
  • 85
  • 140
68
votes
5 answers

UIButton title alignment and multiline support

How do I set the title of a UIButton to be left-aligned, and how can I show multiple lines of text in a UIButton?
Raju
  • 3,459
  • 12
  • 37
  • 30
67
votes
8 answers

Change a UIButton's text (padding) programmatically in Swift

Still learning Swift and don't know Objective-C. I saw that in order to changing a button's text programmatically requires the use of titleEdgeInsets but I am not really sure how to use it. I would like to change the text in the button (padding) in…
KellysOnTop23
  • 1,325
  • 2
  • 15
  • 34
66
votes
3 answers

Change a SF Symbol size inside a UIButton

I am declaring a Button like this : let menuButton = UIButton() After that I am trying to change it's parameter and set his position on the view with the help of LBTATools (a pod) with this function: fileprivate func setMenuButtonUI() { …
Cublax
  • 1,232
  • 1
  • 11
  • 20
65
votes
10 answers

UIButton block equivalent to addTarget:action:forControlEvents: method?

I looked around, but couldn't find this on the internet, nor anywhere in the Apple docs, so I'm guessing it doesn't exist. But is there a iOS4 blocks equivalent API to: [button addTarget:self action:@selector(tappy:)…
Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137
64
votes
8 answers

How to apply a tintColor to a UIImage?

I have a UIImage that is a small symbol that is all black. The UIImage is getting set in a custom UIButton subclass I have. Is it possible to have the image to apply the tintColor to it, so instead of the black image it changes colors to whatever…
aahrens
  • 5,522
  • 7
  • 39
  • 63
64
votes
3 answers

iOS NSAttributedString on UIButton

I'm using iOS 6, so attributed strings should be easy to use, right? Well... not so much. What I want to do: Using a custom subclass of UIButton (it doesn't do anything custom to titleLabel), I'd like to have a multi-line, attributed title that…
mbm29414
  • 11,558
  • 6
  • 56
  • 87
63
votes
12 answers

Change button background color using swift language

I am new to the swift language. Can someone tell me how to change the background color of a button using the swift language?
kalim sayyad
  • 1,076
  • 1
  • 9
  • 13