So I have a few buttons in an application and obviously they can all be pressed and do various things...
My question is, how can you "not display" the colour change or visual aid that happens on screen once a button is pressed?
To be honest, I'm not sure how to word this or which terminology to use, but basically, when a button is pressed, I don't want any change on screen to happen (apart from whats supposed to happen in the IBAction).
It sounds counter intuitive, but I was hoping for a built in function like IBActionPress.Visual = NO; or something like that...
I really hope this makes sense. Thanks in advance.
Try using
yourUIButton.adjustsImageWhenHighlighted = NO;
Related
I have a custom class here that consists of a UIButton inside of a UIView.
The goal of this class is to allow users to have a greater area (being the UIView) to select the button than just the buttons frame itself.
Now when a user taps on the view I want the buttons highlighted image to show... But the problem is, it does not.
I've read many possible solutions to this issue For Example:
Calling: [btnObject sendActionsForControlEvents:UIControlEventTouchUpInside]
This however did not change the buttons highlight.
I also tried just settings the button.highlighted = YES;
But that did not work either.
I have the images for different states properly setup (Normal and Highlighted), I'm sure of that.
I also have the gestureRecognizer working properly as the functionality is great except for the lack of highlight.
Does anybody know if I'm missing any thing special that needs to be done in order to pull off this seemingly very simple task? Surely it's been done many times.
Thank you
You were on the right track. -[UIButton setHighlighted:] is just a flag. What you need to do is call setNeedsDisplay on that button right after you change the highlighted property.
I solved my problem a little while ago and I'm not sure if Kevin Low's answer would've worked too, it very well might have.
But for some reason, a UITapGesture doesn't work well with highlighting buttons as a view transitions (That might be because I didn't call setNeedsDisplay). The gesture that ended up working was the UILongPressGesture with a 0.0 sec for minimum duration.
I have tried to use
var b = button1.getText() to get the text of a button in limejs but it does not seem to work. Can anyone help?
A Glossy Button does not have a getText method as is, but you could alter the library and create it if that's what you need. I'm not sure why you would want to get the text of a button however, it seems trivial to me as it's mostly hard coded. What you could also do is set a listener to the button which then in turn sets a variable to the text you initially placed in the button.
Please take a look at the documentation of LimeJS before asking questions like this, you could easily have spotted the problem :)
I am working on a tab bar application which needs a global title bar with a setttings button attached. I have achieved adding an imageview to the main window, then a label, another image, and finally a button. However, I cannot get this button to fire an action. it is set up like this:
[settingsButton addTarget:self action:#selector(settings) forControlEvents:UIControlEventTouchupInside];
Then the action defined like:
-(void)settings{
NSLog(#"please do something");
}
However nothing happens, the image doesn't even change like it is being pressed. Can i not define buttons in the app delegate this way? is it because the target is not something that is control based? i tried different targets but i must not fully understand what setting a target is. thanks for any help.
P.S.- i tried setting up the method like so as well:
-(void) settings:(id)sender{
}
and calling it by replacing the action with #selector(settings:) to no avail. Thank you.
I solved it. I forgot I changed the view behind the button to a UIImageView. I can't believe I didn't think of this before since this same issue cost me 2 hours the other day. When you have an imageView always remember to set this flag if you want stuff on it:
(someImageView).userInteractionEnabled = YES;
Hopefully I save someone an hour or two of needless headaches.
P.S. Thanks for the speedy comment !
I know I can access a individual button on a actionSheet using a for loop to access the particular button in the action sheet I want, but the thing is, how would I make a green button?
I know each button acts almost identically to a UIButton so how should I go upon making one of my buttons in the action sheet green?
I just need some tips or help with this as it is the last part of my app that isn't done!
Thanks!
When I have needed customizations for UIActionSheets, sometimes I find methods to make it happen simply, but more often I end up having to set up a custom view on way or another. I've added all manners of custom controls with:
[sheet addSubview: myCustomActionSheetController.view];
You might need to set the size as well.
I know about self.navigationItem.rightBarButtonItem.enabled = NO, but how do I make a UIBarButtonItem appear disabled but actually detect when the user taps it? I want to do this in case I want to alert the user what is incomplete.
The way i'd do it is not disable it, but when its 'disabled' set another bar button item there with a disabled looking background and no alternate image for the tap event. Then when it is tapped, show an alert view to tell them that it isn't available:
- (void)init
{
[self setDisabledBarButtonItem:[UIBarButtonItem alloc] initWith...];
[disabledBarButtonItem addTarget:......];
[self setEnabledBarButtonItem:[UIBarButtonItem alloc] initWith...];
[enabledBarButtonItem addTarget......];
}
- (void)timeToDisableBarButtonItem:(id)sender
{
[self.navigationitem setRightBarButtonItem:disabledBarButtonItem animated:NO];
}
- (void)timeToEnableBarButtonitem:(id)sender
{
[self.navigationitem setRightBarButtonItem:enabledBarButtonItem animated:NO];
}
Good UX practises state however that you shouldn't need to tell your user that it is disabled, they should be able to tell without an alert. Easier said than done of course :)
Would love to see a cleaner solution than this, but its the only way I think your going to get it to work.
Hope that helps :)
I had a similar problem, except I was trying to make a disabled button look enabled. I found a much nicer solution that is available in iOS 5.0 - you can use setTitleTextAttributes:forState to control the appearance of your enabled (or in my case, disabled) state, as well as many other states.
API reference:
https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIBarItem_Class/Reference/Reference.html#//apple_ref/occ/instm/UIBarItem/setTitleTextAttributes:forState:
In most cases you won't want to do this. However, in my case it proved necessary. I have a toolbar button that is a document title, and pressing it while in edit mode allows brings up a UITextField to edit the title, but in run mode the title should not be editable while still looking like a title, rather than a disabled button. By changing the text color to match my enabled state, I achieved the look and behavior I wanted without having to swap the button or the action out (and consequently have to synchronize my title text across three places instead of two).