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;
}
Related
I am using Xcode 9.4.1 and I have added a UIButton in storyboard in a new project. Have changed the button to custom and have set constraints.
My problem is there is no change in button appearance when it is tapped. there has always been a default change in uibuttons appearance when it is tapped in earlier projects.
Is it only with me or its a general thing with new xcode?
You can try setting UIButton's selected state properties.
just check state of UIButton in Attributes Inspector set it enable then check type it should be system and not showing then once click on drawing = Show touch bar on Highlight then run your project and see when click is there any effect or not. Hope this is work fine for you.
I use IB and have properly wired up my buttons. I have verified they are properly wired, as some IBAction methods will have buttons hide properly. The issue I have is hiding the UIButtons when it first loads the app. In viewDidLoad I set the button property to hidden, but it doesn't hide it. Thoughts?
- (void)viewDidLoad {
stop.hidden = YES;
play.hidden = YES;
[activity startAnimating];
[super viewDidLoad];
}
After more debugging, the stop button hides but not the play.
It's hard to tell even from the code you posted why this is happening, The best guess will be that somewhere in the next lines of code you set it back to visible = YES mistakably. I would check if there is a method that shows the button that is called before it is needed.
BUT
If the initial state is hidden for your buttons. why don't you simply hide them on IB interface?
Try this
Remove outlet run the code ,test weather it works fine
Remove outlet,add hidden property via IB and run it again and test if it is seen properly.
If it works fine the problem is with code written.
Check the hidden property written via code
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
I am doing an application , using ARC. I add a button to the navigation controller as a subview and then remove it. It works fine on simulator but on device, after using for a long time, the buttons are hidden , but on touching on that area, it responds.
Could it be some memory issue?
Wherever you place button.hidden = YES, also place button.enabled = NO.
I have a UISegmentedControl in a UIView in my popover that I want to disable in some cases. The segmented control is set up with Interface Builder in a nib file. Its IB "Enabled" checkbook is checked.
To disable it, I wrote:
self.segmentedControl.enabled = NO; // or YES when I want it enabled
Which works to the extent that from there on the segmented control doesn't react to touch events.
However, there is no graphic feedback whatsoever. I would like the segmented control to dim (gray out) when it's disabled. I tried to set its highlighted property to NO as well, with no effect.
This should be possible as disabling the UISegmentedControl with Interface Builder produces the dimming effect that I want.
However, if I do that, my code then cannot re-enable it:
self.segmentedControl.enabled = YES;
will not make it enabled: even though it will start accepting touch events again, it will stay dimmed.
It's as if the IB "enabled" check box controller two properties: enabled and dimmed. But what is this dimmed property that I can't find?
What did I miss?
This is in the 4.3 iPad simulator.
(note that I am talking about the whole control, not its individual segments).
Edit: I investigated a bit further and I found out that disabling the segmented control in IB also sets its alpha property to 0.5.
When adding:
self.segmentedControl.alpha = 0.5; // or 1.0 if enabled
My app now seems to behave normally.
Am I right to think that setting the enabled property should also take care of the screen appearance?
I found that this works for each segment:
[self.segmentedControl setEnabled:NO forSegmentAtIndex:0];
The effect is subtle, but it does grey it out. To do all segments:
for(int index=0; index<self.segmentedControl.numberOfSegments; index++)
{
[self.segmentedControl setEnabled:NO forSegmentAtIndex:index];
}
I ran across the exact same problem, with an interesting twist. The interface behaves as you describe it on an iPad running iOS 4.3. However, the segmented control DOES dim in an iPad running iOS 5.0. So, my assumption is that this is a bug that was fixed by Apple in iOS 5.