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
159
votes
22 answers

Make a UIButton programmatically in Swift

I am trying to build UIs programmatically with Swift. How can I get this action working? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let myFirstLabel =…
Benr783
  • 2,860
  • 4
  • 20
  • 28
157
votes
12 answers

UIButton Image + Text IOS

I need a UIButton with image & text. Image should be in the top & text comes under the image both should be clickable.
Codesen
  • 7,724
  • 5
  • 29
  • 31
153
votes
11 answers

How to set the title text color of UIButton?

I tried changing the colors of the text for a button, but it's still staying white. isbeauty = UIButton() isbeauty.setTitle("Buy", forState: UIControlState.Normal) isbeauty.titleLabel?.textColor = UIColorFromRGB("F21B3F") isbeauty.titleLabel!.font =…
coolmac
  • 1,573
  • 2
  • 10
  • 11
152
votes
18 answers

Underlining text in UIButton

Can anyone suggest how to underline the title of a UIButton ? I have a UIButton of Custom type, and I want the Title to be underlined, but the Interface Builder does not provide any option to do so. In Interface Builder when you select the Font…
RVN
  • 4,157
  • 5
  • 32
  • 35
149
votes
15 answers

How to make UIButton's text alignment center? Using IB

I can't set the title of UIButton using IB as center. My title is multi line.It is giving like this one But I want like this one I have given space in this but I don't want to do that. As it is not aligned exactly for some cases and I know there…
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
148
votes
17 answers

iOS: UIButton resize according to text length

In interface builder, holding Command + = will resize a button to fit its text. I was wondering if this was possible to do programmatically before the button was added to the view. UIButton *button = [UIButton…
Oh Danny Boy
  • 4,857
  • 8
  • 56
  • 88
146
votes
18 answers

Get button click inside UITableViewCell

I have a view controller with a table view and a separate nib for the table cell template. The cell template has some buttons. I want to access the button click along with the index of the cell clicked inside the view controller where I have defined…
ankit_rck
  • 1,796
  • 2
  • 14
  • 24
139
votes
12 answers

How to change UIButton image in Swift

I am trying to change the image of a UIButton using Swift... What should I do This is OBJ-C code.but I don't know with Swift: [playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
Lop Hu
  • 1,443
  • 2
  • 9
  • 8
136
votes
16 answers

How to make a simple rounded button in Storyboard?

I just started learning iOS development, cannot find how to make simple rounded button. I find resources for old versions. Do I need to set a custom background for a button? In Android, I would just use a 9 patch, but I know iOS does not have this…
Gintas_
  • 4,940
  • 12
  • 44
  • 87
133
votes
9 answers

Using Tint color on UIImageView

I have my own subclass of UIButton. I add UIImageView on it and add an image. I would like to paint it over the image with a tint color but it doesn't work. So far I have: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; …
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
127
votes
5 answers

Is it possible to adjust x,y position for titleLabel of UIButton?

Is it possible to adjust the x,y position for the titleLabel of a UIButton? Here is my code: UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [btn…
RAGOpoR
  • 8,118
  • 19
  • 64
  • 97
126
votes
14 answers

Attach parameter to button.addTarget action in Swift

I am trying to pass an extra parameter to the buttonClicked action, but cannot work out what the syntax should be in Swift. button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside) Any my buttonClicked…
iphaaw
  • 6,764
  • 11
  • 58
  • 83
124
votes
16 answers

iPhone UIButton - image position

I have a UIButton with text "Explore the app" and UIImage (>) In Interface Builder it looks like: [ (>) Explore the app ] But I need to place this UIImage AFTER the text: [ Explore the app (>) ] How can I move the UIImage to the right?
Pavel Yakimenko
  • 3,234
  • 4
  • 28
  • 33
118
votes
8 answers

Get position of UIView in respect to its superview's superview

I have a UIView, in which I have arranged UIButtons. I want to find the positions of those UIButtons. I am aware that buttons.frame will give me the positions, but it will give me positions only with respect to its immediate superview. Is there is…
Shailesh
  • 3,072
  • 3
  • 24
  • 33
115
votes
11 answers

Swift - UIButton with two lines of text

I was wondering if it is possible to create a UIButton with two lines of text. I need each line to have a different font size. The first line will be 17 point and the second will be 11 point. I've tried messing with putting two labels inside of a…
Scott
  • 1,370
  • 2
  • 9
  • 16