UIAlertController changes UIButton colour after dismiss - ios

Whats happening is that I am making a post request using Alamofire.
Now when I hit api the button colour is light grey but after I show some message using AlertController and then Click on Ok Button the colour of button changes to Blue. Now in Identity inspector, button has UIButton set as class. I don't know whats going wrong I am not changing buttons background at any stage for selected, highlighted or other states.
There is no button category as well.
Attached images display step by step process.
pop is showing
blue background button

A bit late to the conversation, but for everyone looking for the answer, changing button.tintAdjustmentMode = .normal will ignore tint changes.

Related

Why is UIButton.titleLabel?.text always switching back after I changed it in Swift 5 (UIKit)?

I ran into an issue with my UIButton.
After the User presses the button, it activates an IBAction which is supposed to change the titleLabel.text of my UIButton.
self.btnAppleHealthKit.titleLabel?.text = "Already pressed."
Whenever I press the button, the text changes for about a quarter second to "Already pressed", but switches back immediately to the previous text.
Important Note: The whole thing is inside a completion handler but I wrapped it into DispatchQueue.main.async { }
Can you guys think of an idea why this error appears?
Thanks for your help in advance.
It seems, UIButton does not allow to configure text or color of titleLabel.
From apple doc.s
Do not use the label object to set the text color or the shadow color.
Instead, use the setTitleColor(:for:) and setTitleShadowColor(:for:)
methods of this class to make those changes. To set the actual text of
the label, use setTitle(_:for:) (button.titleLabel.text does not let
you set the text).

Xcode disable UIButton title fade when tapped

When I tap or hold down on any of my UIButtons, their alpha seems to fade to about 0.1. I never added this functionality in, so I'm assuming it's automatic.
How do I disable this so that my button doesn't fade when tapped or held down? I want my button to remain at alpha 1 all the time.
I've tried button.adjustsImageWhenHighlighted = NO; to no avail, as well as a few other suggestions on here.
Did you try using the same image for both the "normal" and "highlighted" states?
Maybe showsTouchWhenHighlighted also affects the situation.
Are you using background images for your buttons too?
Are you disabling the button upon tapping? Disabling also affects appearance (unlike userInteractionEnabled).
Are you using IB/Storyboards?
As you can see, there is a number of factors that can play a role into what's happening.
Any code you can show with specifics of your situation?
Edit: If you are not using an image (you mentioned adjustsImageWhenHighlighted), then just set the button type to "custom" in IB. You won't get the system provided "default" behavior.
just uptick the Disabled Adjusts Image in your MainStory Board in your buttons configuration next to the Drawing section

UIButton and UIControlStateHighlighted issues when starting app

for my UIButton I have its Default State Config set to buttonLong_beige.png and Highlighted State Config set to buttonLong_beige_pressed.png everything works as it should when the button is pressed, I press the button and the image changes from buttonLong_beige.png to buttonLong_beige_pressed.png each time i press it but the issue is when the app starts... before the button is even selected, it is already highlighted even though I never touched it yet... but once I press the button it returns to buttonLong_beige.png and then changes back and forth each time its pressed..... I have no code to display since this is all done in the storyboard, im very confused...
Check this in the "atribute inspector"
Its looks thats your button starts highligted, so un-check that.

iOS: How to disable Fading in and out effect of UIButton

First of all, sorry for the title and asking this incredibly question but I simply couldn't figure it out. Also, since it is not related to code, I don't have code to show
I am working on an app and using iOS7 and I created a button from IB, set its background image to an image I designed. Connected it with header and set its touch up inside action as an IBAction
Yet, here is my problem. Whenever I click on the button, as an effect the image fades half transparent. I do not want this default attribute. I checked all the states on IB (highlighted, disabled, selected) and couldn't figure it out.
If I create the same button programmatically, only the text color changes, however when I set the background image, image fades (perhaps to indicate the button being pressed). How can I remove this effect?
A bit late but I believe this would solve the problem
in the xib file, set the button's type to Custom.
My button was set to system and when pressed on, it shows transparency and has a little fade in effect. Once I changed it to custom this effect is gone.
This cannot be changed once button is created. only in xib or when the button is first created.
have you tried this one yourButton.adjustsImageWhenHighlighted = NO?
If you set same background-image/background-color for every buttons states in IB (highlight, disable, selected) you will not get any fading in UIBUtton when you press it. You can set text color for every states also. If needed you can set different colors for every state and check the press action.
Hope the answered you expect. Thanks
Storyboard Solution
1:set button type to custom
2:uncheck "Highlighted adjusts Image"
If you want fading in & out effect your UIButton Type Should be a system, not custom.

ios navigation buttons

I'm doing a custom nav in ios for the first time. I have six buttons laid out in a row. When I tap the button, I want the image to change. However, the button is not togglable. The only way a button can be unselected is if another button is touched. Only one button can be active at any given time.
My idea:
use UIButtons
change UIButton image on touch
keep track of the active button inside the navigation class
when an inactive button is touched, make the currently active button inactive and turn the touched button to active
I want the end product to work like a custom TabBarController, but without switching layouts. I just want to edit the content in the current ViewController.
Is there a better way to do this?
You could just use the UISegmentedControl, which has that functionality already. If you need to significantly customise the look and feel though, your UIButton solution sounds fine.
I setup the UIButtons in the Interface Builder like so:
Default with unselected background image
Disabled with selected background image
On touch, a button is self.enabled = NO which makes the UIButtons look change. However, the button goes dim, so I also implemented self. adjustsImageWhenDisabled = NO.
This way a button can't be re-selected once it's "active".

Resources