Avoiding making a NSButton transparent / see-through when isEnabled is false (disabled) - swift

A regular NSButton seems to be transparent if it’s disabled.
Image shows a Button with style 'push'
However, I want to disable the Button without the transparency.
I’ve tried to programmatically set the alphaValue to 1.0 but it seems that the NSButtons cell (controlView) as well as all other subviews are already at an alphaValue of 1.0.
Also, there’s nothing like userInteractionEnabled or adjustsImageWhenDisabled (both recommended here) I could use like in iOS.
How can I disable a NSButton without the standard transparency?
EDIT: Also a 'textured push' button appears to be transparent:

If you don't need the title, and will provide your own button image, you can use setImageDimsWhenDisabled to disable transparency in NSButtonCell's image when it is disabled. Here is the code:
[buttonCell setImageDimsWhenDisabled:NO];
NSButtonCell is the subview of NSButton. But as I said, the title will still be "dimmed" a little bit, and also its background. But since image if on top of the background, you won't see the transparent background.
Another way (avoid subclass NSButton) is to have your own state tracking variable for button. When the state is disabled, dismiss any click event. Sample framework of code is like this:
- (IBAction)clickOnButton {
static BOOL isEnabled = YES;
if (isEnabled) {
// Handle click event here...
}
isEnabled = !isEnabled;
}
This may show the highlight when clicked. You can disable highlight also. But this is not a good idea if you have many buttons. If you have many buttons, subclass NSButton is the best choice.

Related

How can I highlight the BarButton in navigation bar without tapping it?

Typically, the UIBarButtonItem will be highlighted when we tap it.
However, I intend to show the users that the action is automatically done for them when the view is loaded after 4 sec.
So I want to highlight the Button without tapping it.
How can I achieve that?
For a UIVIew object such as a UIButton, you can either use the following code Glow category on UIView that adds support for making views glow or use this example.
If you are using the first one, you can just call startGlowing and stopGlowing. When you call startGlowing, the view will start to pulse with a soft light, this effect is removed when stopGlowing is called. Check this.
For UIBarButtonItem, you might have to use the solution provided here.

UIBarButtonItem Done State Without Border

I have a UIToolbar where all the buttons have a style of UIBarButtonItemStylePlain. One of these buttons toggles a setting in my app and I would like to have some type of Selected state when that feature is enabled.
Since I am not using bordered buttons, setting the style to UIBarButtonItemStyleDone would not work because the button would not match. Is there an easy way to change to color of the icon on the button?
For a sample, look at the location button in the Maps app on the iPad. It does exactly what I am looking for.
Sure thing. You can set the background image with initWithImage:style:target:action: or supply a custom view with initWithCustomView:

Disable touch animation in UIButton in iPhone

I want to disable the animation of button is touch down or selection. I want to mimic the feature that selection is happening on label. I am comfortable with the properties of button compare to uilabel because i can give my background image and it also help me in more issues.
Please help me in this?
I think what you need is to unselect the "Highlighted adjusts image" option in Interface Builder:
Disable the user interaction of your button.
myButton.userInteractionEnabled = NO;
2018 people, Swift 4.0:
Setting the button's adjustsImageWhenHighlighted property worked. Need this in my custom UITabBarController (e.g. large center tabBarItem).
set your button type as custom.
myButton.buttonType = UIButtonTypeCustom;

touch effect for Button in iphone

how can i just change the color,of a button when i set the focus on the button in iphone.
I mean to say , for example we have 5 buttons, and i am just setting the focus on each of the button. i want those buttons to be higlighted with different color.
but when press or touch up inside the utton, the navigation is made to the respective forms, that is set for that button.
you can write method, for example, let it be
- (void) changeButtonState:(UIButton*) buttonToChange;
then you can call it in your onBtnClk method for button you need. in that method you can change image for your button's UIControlStateNormal mode. and if I understand right, you can use toolbar or tabbar instead of buttons.
Guess you have already asked this issue differently here..
But have you checked the answer?? You can use any of those methods at your will!

iPhone dev: adding an overlapping label to the image

I'm trying to figure out a best way to implement the picture-editing capability shown in the native address book app on iPhone.
On the built-in address book, this is how the picture looks like before editing:
qkpic.com/2f7d4 http://qkpic.com/2f7d4
And after clicking edit, notice how "Edit" overlay is added and the image becomes clickable:
qkpic.com/fb2f4 http://qkpic.com/fb2f4
What would be the best way to implement something like this? Should I make the image a button from the beginning and have tapping disabled at first? If so, what steps are required to add an overlay/label to the image (in above example, gray border + the text "Edit" is added)
The easiest way is to use Interface Builder, create a container view, then add a UIImageView and UILabel as subviews to it. You would position and style the text and the image but set the UILabel to hidden. Make the whole container view respond to touches. It's easy to do since UIView is derived from UIResponder so all you have to do is override touchesEnded. Whenever you want to change the text label, just set the UILabel to hidden=NO.
There's more to it, however. Notice how the image has rounded corners? You'll want to override the UIImageView's drawRect method to implement a custom drawing routine to do that. There's lots of sample code around and it wasn't part of your original question so I'll stop here.