UISegmentedControl.enabled = NO doesn't dim it - ios

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.

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

Showing / hiding accessibility elements in an overflow menu when opening a custom UITableViewCell

I’m implementing accessibility in a custom UITableViewCell class. I have a fairly simple overflow menu with a couple of buttons inside it, which are hidden until an ellipsis button is pushed that slides open and closes the overflow.
In my cell's initialiser I’m setting the accessibilityElementsHidden of my overflowContainer to YES. This seems to work, when scrolling through using VoiceOver, those views are skipped.
Then, when opening the cell, in the completion handler of the UIView animation, I set that same accessibilityElementsHidden of the same overflowContainer to NO. This doesn’t seem to have any effect, those elements are still skipped.
I’ve also tried posting UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil) before / after / when changing the accessibilityElementsHidden BOOL, but this also appears to have no effect on the situation.
Basically I’d like to toggle accessibilityElementsHidden on a couple of UIView instances at a specific point. Could anyone let me know what I may be doing wrong?
Here’s the code I fire when the overflow opens:
- (void)cellOverflowDidShow:(MyCell *)cell
{
self.overflowContainer.isAccessibilityElement = YES;
self.firstButton.isAccessibilityElement = YES;
self.secondButton.isAccessibilityElement = YES;
self.thirdButton.isAccessibilityElement = YES;
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton);
}
I fire the opposite when closing the cell (set all to NO and post notification again). And when initializing the cell, all I set is:
self.overflowContainer.isAccessibilityElement = NO;
Absolutely no idea why it shouldn’t be working, it appears I’m doing everything 100% correctly. If I don’t set the line in the initializer, the buttons all appear accessible (all the time). So it appears that the first call, be it YES or NO, works, but any subsequent ones are ignored.
In the visible state, you declare the overflow container to be an accessibility element. Thus, VoiceOver will allow the user to focus it rather than navigate child elements. Instead of toggling whether it's an accessibility element, keep self.overflowContainer.isAccessibilityElement set to NO and toggle the accessibility of its children, firstButton, secondButton, and thirdButton.
A shorthand for setting the accessibility of child elements is accessibilityElementsHidden. Try setting self.overflowContainer.accessibilityElementsHidden to NO when the view appears and YES when it disappears.
You may still need to trigger a layout change notification, regardless.

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;
}

Button remains visible when disabled

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

How to change border color of UIPopoverController? [duplicate]

I'm working on an iPad application and I'm using UIPopoverControllers. I'm at the part where the app needs to be branded and styled and i'm wondering how to change the color / tint of the UIPopoverController? Standard is dark blue but it needs to be another color..
is this possible?
Greets, Thomas
This is possible starting in iOS 5.0 by subclassing the abstract class UIPopoverBackgroundView and assigning your subclass to the popoverBackgroundViewClass property on your UIPopoverController instance. Unfortunately there is no tintColor property as the popover needs to use images for it's arrow and border in order to achieve smooth animations during dynamic resizing. You can learn more about how to customize the appearance of a UIPopoverController in the UIPopoverBackgroundView Class Reference
It's impossible for now.
It's what I call the "Box in a Box" model. You get control of the box inside of the box (the UIViewController inside of the UIPopoverController), but you have very limited control over the actual popover itself. Outside of the arrow direction and the size, you can't change much else. There are also options for a modal effect popover, which dims everything else when it shows up, but I haven't tried to get it working.
I'm sure you've noticed there is no UIPopover class by now.
The answer you want to hear:
If you really want to style one that bad, just write your own. It's really not that hard.
The link you want to click:
Cocoacontrols is an index of iOS and OSX components available on GitHub, they have some popover stuff.
iOS 7 introduces backgroundColor property of UIPopoverController which affects/includes the navigation background color as well as arrows of popover.
#property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);
Usage example:
if ([self.popoverVC respondsToSelector:#selector(setBackgroundColor:)]) { // Check to avoid app crash prior to iOS 7
self.popoverVC.backgroundColor = [UIColor greenColor]; // [UIColor colorWithPatternImage:#"..."] doesn't reflect the color on simulator but on device it works!
}
Note - As of now (iOS 7.0.3), in some cases (like set color using colorWithPatternImage:), the simulator (and even some devices) doesn't honor the color.
Throwing my hat in here;
I've leveraged UIPopoverBackgroundViews in iOS 5+ to add a simple tintColor property onto UIPopoverControllers.
PCPopoverController: https://github.com/pcperini/PCPopoverController
I try to trick it by customizing the view controller inside the popover and then hiding the popover border using this code:
UIView * border = [[insideViewController.view.superview.superview.superview subviews] objectAtIndex:0];
border.hidden = YES;
The app is actually still in development so I'm hoping other people will comment on this solution.
check out these latest projects leveraging UIPopoverBackgroundView
https://github.com/CRedit360/C360PopoverBackgroundView
https://github.com/GiK/GIKPopoverBackgroundView
from ios 5 onward it is can be done, here is a library
https://github.com/ddebin/DDPopoverBackgroundView
just look at the documentation , and it is quite easy
good luck
You can use Elegant Popover cocoapod for just that. You can customise shape and colour of the arrow and the popover itself. Also, you can add colourful borders to the popover.
I know this is a lousy constructed answer, but I've just been playing with the UIPopoverController's views. They do exist.
The only way to access them is from your view that is sitting in the UIPopovercontroller.
I have a navigation controller so I follow this hierarchy
UIView *test = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
UIView *test2 = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
test.backgroundColor = [UIColor greenColor];
test2.backgroundColor = [UIColor greenColor];
This isn't exactly the end goal, but it is really close.
you'll find that the_view_in_the_popover.superview.superview (maybe just one superview if you are not reaching out from a navigation controller view) is a UIPopoverView. If you cast it as a UIView and treat it as a UIView you're not really breaking any rules. I guess that is really up to apple though.
Remove UIPopoverController border:
NSArray* subviews = ((UIView*)[popupController.contentViewController.view.superview.superview.superview.subviews objectAtIndex:0]).subviews;
for(UIView *subview in subviews){
[subview removeFromSuperview];
}

Resources