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
35
votes
16 answers

Get button pressed id on Swift via sender

So I have a storyboard with 3 buttons I want to just create 1 action for all those 3 buttons and decide what to do based on their label/id... Is there a way to get some kind of identifier for each button? By the way they are images, so they don't…
matt
  • 2,312
  • 5
  • 34
  • 57
34
votes
4 answers

UIButton with GradientLayer obscures image and darkens gradient

I have an UIButton here where I'd like to have a gradient as the background below the image (symbol with transparent background), but I'm facing two different problems. First of the CAGradientLayer seems to overlay on top of the image no matter how…
Christian A. Strømmen
  • 3,181
  • 2
  • 25
  • 46
34
votes
7 answers

UIScrollview with UIButtons - how to recreate springboard?

I'm trying to create a springboard-like interface within my app. I'm trying to use UIButtons added to a UIScrollView. The problem I'm running in to is with the buttons not passing any touches to the UIScrollView - if I try to flick/slide and happen…
Patrick
  • 637
  • 2
  • 8
  • 10
34
votes
3 answers

Can I get the element by Tag from iOS?

I want to get back a button, I've already assign the tag to there, how can I do so?
DNB5brims
  • 29,344
  • 50
  • 131
  • 195
34
votes
5 answers

ios 8 - buttons in horizontal scroll view intercepting pan event - scroll does not work

I have a horizontal scroll view with a line of buttons. The scroll view will not scroll unless I do an extremely fast swipe. If I set the buttons to userInteractionEnabled = NO, then the scrolling works as expected, but of course, then the buttons…
Mike M
  • 4,358
  • 1
  • 28
  • 48
34
votes
1 answer

Tint UIButton's image from interface builder with UIImageRenderingModeAlwaysTemplate

I have a UIButton whose image property I'm setting from interface builder. I want this image to be tinted with the superview's tintColor. With code, I can set the image's rendering mode to UIImageRenderingModeAlwaysTemplate, but how do I do this…
rounak
  • 9,217
  • 3
  • 42
  • 59
34
votes
9 answers

UIButton fails to properly register touch in bottom region of iPhone screen

I have an app with many different buttons arranged in a calculator like, square / rectangular format. It is actually extremely similar to the default iOS calculator. There are approximately 6 rows with 4 columns each of buttons. Problem The problem…
Iowa15
  • 3,027
  • 6
  • 28
  • 35
34
votes
5 answers

Stretch background image for UIButton

I got texture, which really shorter, than my UIButton. I got this texture: And i should create this button: How should i stretch (not tile), this texture? Stretching in horizontal direction Thnx
Eugene Trapeznikov
  • 3,220
  • 6
  • 47
  • 74
33
votes
11 answers

Display activity indicator inside UIButton

I would like to change the content of a UIButton to an ActivityIndicator after it is pressed. I know buttons have an imageView and a titleLabel, but I don't know how to put an activity indicator in any of them. This is how I create activity…
jood
  • 2,188
  • 2
  • 21
  • 32
32
votes
1 answer

Change in Button text color not reflecting

I am facing a weird issue. I am changing the text color of my button when it is highlighted but visually no change at all. [myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [myButton setTitleColor:[UIColor…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
32
votes
3 answers

How do you set an Attributed Title Color for State in Swift

I'm able to set the attributedTitle for a UIControlState, but how would I set the attributed title's color for a UIControlState?
landing
  • 449
  • 1
  • 4
  • 8
32
votes
22 answers

UIButton in Swift is not registering touches

I'm trying to create a UIButton using Swift. It compiles fine and I can see my button in the simulator, but when I click it, nothing happens. This is the code I am using: let settings = UIButton() settings.addTarget(self, action: "touchedSet:",…
Phillip
  • 1,205
  • 3
  • 15
  • 22
31
votes
2 answers

set title color for UIButton when highlighted iOS 7

I have the following code in a viewController, all the outlets and action are hooked up correctly. the WHITE and PURPLE are UIColors that I've defined constants for. I've also set the UIWindow's tintColor to PURPLE and that propagates down to the…
Adam Langsner
  • 1,276
  • 1
  • 15
  • 23
31
votes
8 answers

How to deselect a segment in Segmented control button permanently till its clicked again

I have a UISegmentedControl with 4 segments. When it is selected, it should maintain the selected state. When the same segment is clicked again, it should deselect itself. How to achieve this?
Pradeep Rajkumar
  • 919
  • 2
  • 12
  • 27
31
votes
1 answer

Extended UIButton border is not initially drawn

I am trying to create a custom UIButton which extends from UIButtonType.RoundedRect. My added functionality is working, but there is an issue with the initial rounded border state of my button. The border of my extended button is not drawn until…
Scott
  • 21,211
  • 8
  • 65
  • 72