Questions tagged [uicontrolstate]

31 questions
100
votes
12 answers

is it possible to update UIButton title/text programmatically?

I have a UIButton, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I'd like to update the title/text of the UIButton to reflect the new state. I'm calling: [myButton setTitle: @"myTitle"…
George Armhold
  • 30,824
  • 50
  • 153
  • 232
44
votes
4 answers

How to set the alpha of an UIImage in SWIFT programmatically?

I found a lot solutions here but not for Swift, and I know you can do this with a UIImageView, but in my case i need an programmatically set alpha transparent background image for an UIButton. Best would be an UIImage extension! let img =…
Peter Kreinz
  • 7,979
  • 1
  • 64
  • 49
15
votes
2 answers

Whats the difference between `UIControlState()` and `UIControlState.normal` when configuring an object

I usually seen UIControlState.normal used, for example to set a titleColor on a UIButton object that will be used among all control states, as the UIButton. setTitleColor docs says: In general, if a property is not specified for a state, the…
AamirR
  • 11,672
  • 4
  • 59
  • 73
15
votes
1 answer

Whats the use of UIControlState "application" of UIButton?

I went through the apple doc too but it just states that its Additional control-state flags available for application use. Its just a getter method so when does it get set?
Apogee
  • 689
  • 8
  • 19
14
votes
6 answers

UIButton - On touch change image

When I touch the button at that time I want to change image & when i release the touch button image is as it is. I want to apply below code but it's not with my expectation. please give me any suggestion..... -(IBAction)actionEnter:(id)sender{ …
Sam007
  • 1,385
  • 3
  • 17
  • 32
10
votes
2 answers

How to change UIButton state programmatically in Swift

I develop app for drawing on screen. I have toolpanel with bunch of buttons. Some of them have to become disabled or pressed depending on current user action. How can I change UIControlState of buttons programmatically considering that "state"…
Oleh Liskovych
  • 991
  • 3
  • 13
  • 31
4
votes
7 answers

How to set a UIButton as both Selected and Disabled

Attempting to toggle both the selected and enabled attribute on a UIButton, therefore creating 4 potential states (Selected & Disabled, Selected & Enabled, Unselected & Disabled, unselected & Enabled). In viewDidLoad I define the the images for the…
user1905842
  • 165
  • 1
  • 13
3
votes
3 answers

Swift - Toggle UIButton title when selected

I'm looking to implement a button that can be used as a tickbox and enablers the user to toggle the tickbox in an on/off fashion (unticked/ticked). Currently I've set up my button using the attributes inspector including the 'Title' as "X" and the…
Rich Townsend
  • 571
  • 1
  • 5
  • 21
3
votes
1 answer

setTitle(_ title: String?, for state: UIControlState) where is .Normal state?

I'm updating my app to Swift 3 with iOS10 on Xcode 8 and I get an error on: Btn.setTitle('str', forState: .Normal) .Normal is not an enum type of UIControlState any more. Which type of UIControlState should I use for this state? Apple enum is now…
Edgar Georgel
  • 602
  • 1
  • 7
  • 17
3
votes
3 answers

UIButton titleColor upon selection and highlight

I'm trying to set a UIButton's titleColor to a certain color when it is selected and when it is highlighted, however, I need to set the button to be selected when the user touches down on the UIButton. I've set it up like so: [button…
RileyE
  • 10,874
  • 13
  • 63
  • 106
2
votes
1 answer

Is there something like RequestLocal (like ThreadLocal)?

In C# there is a class ThreadLocal. You can use it to define a static field that only exist within the scope of a thread. I am looking for something similar for use in an ASP Custom Control. I need to define a static field that is shared between all…
2
votes
0 answers

UIButton: manually calling touchesBegan does not set isHighlighted

The isHighlighted property on UIButtonis mostly analogous to whether the button is pressed or not. The Apple docs are vague about it: Controls automatically set and clear this state in response to appropriate touch events. …
MH175
  • 2,234
  • 1
  • 19
  • 35
2
votes
2 answers

Make UIButton's state change to UIControlStateSelected on TouchUp

I've noticed that if I do something like this [self setTitle:@"Follow" forState:UIControlStateNormal]; [self setTitle:@"Following" forState:UIControlStateSelected]; The button will start off with "Follow". I press it, and when I release my finger…
JVillella
  • 1,029
  • 1
  • 11
  • 21
1
vote
2 answers

Strange state change(UIControlState) of UIButton

I got a strange UIButton result while understanding concept of UIControlState. Here is my simple code related to UIButton. import UIKit class ViewController: UIViewController { let normalBtn: UIButton = { let button = UIButton() …
Changnam Hong
  • 1,669
  • 18
  • 29
1
vote
2 answers

I want to change UIButton Image when tapped on it

I have 2 buttons in header on CollectionViewController. When i tap on one of them i'm changing an image of this buttons using UIControlState -> .normal .selected. override func viewDidLoad() { super.viewDidLoad() collectionView.delegate =…
SunCode
  • 43
  • 10
1
2 3