Button remains visible when disabled - ios

I have created a custom button in IB which performs a play video function for me. But sometimes when the video is not available I want to have the button disabled & invisible.
the button is linked to the code by having dragged the IBOutlet.
so when I do [playButton setEnabled:NO] it gets disabled, but it's still visible, although becomes transparent. I need it completely disappeared. Any ideas?

Set playButton.hidden = YES to hide it.
Disabling only prevents user interaction

Related

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

Button Disable Xcode 5.1.1

I am getting a very weird issue while disabling a button in Xcode 5.1.1 and iOS SDK 7.1.
My button gets hidden when I disable the button in - (void)viewDidLoad or - (void)viewWillAppear:(BOOL)animated or in the nib.
The same code is properly working for iOS 7.0 and below.
myButton.enabled = NO;
Is this an Apple bug?
I had tried in different projects also but result is same.
I am using it Xcode 5.1 and it works perfectly on iOS 6 to iOS 7.1.
possibility is:
check whether the button is system or custom. it should be custom always.
Try making the button as myButton.enabled = YES; and see whether the button hidden in iOS 7.1.
Then check whether in nib file, you have set clear color for disabled state of the button.
May be your button is placed below another ui object (i.e. UIView), so it is hidden and disabled. If another view's user interaction is enabled, and this view happens to be above the button, then touch event is taken over by that view. Another issue can be that your button is beyond super view's bounds and this super view has clipToSubview enabled.
Actually the problem exists while i am setting the image. I am setting the image of each button using SpriteSheet. The image gets added dynamically after slicing and resizing in background. So whatever the state of button is it just set's the image of Disabled and normal state.
Now to resolve this i checked whatever the state of button it just sets its
if (myButton.state == UIControlStateDisabled)
{
myButton.enabled = YES;
[myButton setImage:returnImage forState:UIControlStateNormal]; // return Image is the image which i get from sprite sheet after slicing and resizing.
myButton.enabled = NO;
}

How to create a clickable button when it is below another view? (iOS)

My ViewController contains WebView and invisible button over (or below) the WebView. (see image). I want that the button to be clickable. But(!) in the case there are some links in the WebView, the links should be clicked, not the button.
How can I do it?
Similar issue discussed here:
Add UIButton in a UIWebView
However, in my case, I need links that are clickable also not be scrolling enabled.
If all you need is to be able to still drag the UIWebView around while still being able to receive a button press on a certain part on the view, you don't need to place a button below it in order to achieve that.
UIButton can still be able to receive touch even if it is completely transparent.
yourButton.backgroundColor = [UIColor clearColor];
[yourButton addTarget:self action:#selector(pressed)forControlEvents:UIControlEventTouchUpInside];
This way the button would only receive the press and will not affect your dragging of the web view - it will ignore the dragging but respond only to the press.
Tested on a scrollable view with a clear UIButton.
Hope this helps.

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.

Creating a custom toggle with UIButton in Interface Builder

Is this possible? It seems shoddy for it not to be.
I'm trying to create a toggle button (not a UISwitch) in IB. For example a mute button, when muted would have some indication that sound is disabled, when you hit it, that indicator disappears (but still the same underlying graphic), and toggles between these states each time it is pressed.
This functionality can be achieved using the selected property, however you can't change the Selected AND Highlighted property in IB like you can in code, so whenever the button is pressed, no matter the state, the highlighted image is the same, which looks terrible and glitchy.
Is there a way to fix this with just IB, or do I have to make a custom class to avoid manually loading in all these buttons?
Have you thought about subclassing UIButton to add in the things you need?

Resources