I'd like to create a UIButton with an image that has no borders (a la UIButtonTypeInfoDark) but that highlights when you tap it. How can I do this?
Create a UIButton in interface builder, change the type to custom (and select your image). Add an IBOutlet, then in your viewDidLoad set showsTouchWhenHighlighted to YES.
Related
I put a UIButton on a UITableViewCell and set its showsTouchWhenHighlighted property to YES. The cell's selection style is UITableViewCellSelectionStyleNone. I have a selector that gets called when the button is tapped and it's working fine, so the button is getting the touch events fine. However, button doesn't show the highlight effect when touched.
When I put this button on a UIView, the highlight effect works.
How can I make this work when the button is placed on the cell?
Are you adding the button to the cell or cell.contentView? The contentView property behaves more like a regular UIView, that might solve your problem.
You need to set 'delaysContentTouches' to NO on the Table View
I built a Custom Cell in IB and in it created a view that represents a button. It has Labels and ImageViews in it.
I want to know if there is a way to make that view act like a button. That is, show a shadow and call a method when is pressed.
Yes. Just implement tableView:didSelectRowAtIndexPath: and you can do everything you could do in a button action #selector.
As for the shadow and the rounded rectangle button feel, if you use a single cell in a section with UITableViewStyleGrouped, it will be pretty close.
The best is to make it a button. You can use UIButtonTypeCustom and set the background to the cell you've created.
You can use UITapGestureRecognizer and pass the event through a delegate or use UIControl which is a subclass of UIView but with UIButton tap events like touchUpInside and so, and then pass the event with a delegate to your view
I have a subclass of UIControl and within the control I am adding a UILabel and UIImageview to constitute my button.
As a subclass of UIControl, I believe I am unable to utilize the method '[doSomethingButton setBackgroundImage:stretchableButtonImagePressed
forState:UIControlStateHighlighted]' to set the the UIControl to a different image when clicker
How can I mimic a button's reaction to a user's touch i.e. (UIControlStateHighlighted)
Yes, you are right, the setBackgroundImage:ForState method is a method for UIButton.
The easiest to achieve your goal would be to update the imageView && label states in the action selector of your UIControl.
A subclass do all the works which original works. You can directly set the UIImage for highlighted state to your subclassed control.
I have two UIButton's and I want to be able to have the user click one of the UIButton's and drag it over to another UIButton and have the title of the UIButton moved from the first UIButton to the second one. Is that possible? Thanks.
The title is an element of UIButton, so you can't use any predefined methods to do this. You'd have to create custom implementation where you added a draggable UILabel on touch, then set the button's title to match on release - or something like that.
I have created another answer that will at least get you on your way, it implements the press, the drag, and the up events for a button, where you are trying to recognize another button that you have dragged to!!!
Xcode iOS push down button and drag then up on a second button
Look at the answer provided by me!
During a time in my app - I make a button a button not enabled
myButton.enabled = NO;
The problem is that I've made my button in IB with an image, and just a UILabel overtop of it.
The label does not grey out when the buttons does.
In IB - is there a way to link the label to the button?
This is not possible without you doing the linking action yourself, as #Eiko rightly pointed out.
It sounds like you need to make your image the background-image of the button, so you can have your label as the button text, like it is intended to be used. Then you can specify colors, fonts & images for all 4 possible states.
If you decide to invent the wheel yourself, by keeping button and label as separate objects, you will have to invent everything around it as well.
You can add another outlet in your code, i.e. IBOutlet UILabel *yourLabel;
Then link this outlet to your label, same procedure as linking the button.