How to turn off button shadow on button press of UIButton? - ios

I've created a UIButton in InterfaceBuilder. When a user presses the button, the entire button is shaded grey. Is there a way to alter this behavior so the button is no longer shaded grey when the button is pressed?

Uncheck "Highlighted Adjusts Image" in Interface Builder.
Alternatively, set the adjustsImageWhenHighlighted property of the UIButton to NO.

Change the button type to custom from system in the attributes inspector of the button

Related

UIButton within UITableViewCell is Tappable(Getting proper event) But the issue is tap effect is not visible

I have a custom table view cell with UILable and UIButton which is working fine I am getting proper event on button tap, but the issue is tap effect of button is not visible in UI.
Edit - Functionality wise button is working fine but the issue is that on tap, tap effect is not visible see below attached image.
I am expecting below same smooth touch for button which is within tableview Cell -
add this on your button showsTouchWhenHighlighted and check once
button.showsTouchWhenHighlighted = TRUE
You can set the Text Color e.g Light Gray Color for the button's highlighted state in storyboard.
It will give a tap effect to your button.

UIAlertView Button outside of UIAlertView

I want to use the UIAlertView Button style outside of the UIAlertView in my View Controller. Again, to be clear, I don't want the button inside the UIAlertView, I just want the button style in my own View Controller.
Does the iOS SDK provide this functionality out of the box, or would I have to make my own custom button to replicate the one of UIAlertView?
The two things you're looking for can be easily achieved in Interface Builder, without even needing to subclass UIButton. They're simply settings within the UIButton class.
Button Size/Padding
To change the padding around the text of a button, the easiest way is simply to change the size of the button. You can do this programmatically, by altering the button's frame, or in Interface Builder by simply dragging the edges of the button to the appropriate size.
Alternatively, you can alter the font size of the button's label, again either programmatically or in IB, to give more room within a button of a given size. Also check out the "Line Break" property, which determines how the button handles text that is too long to display.
Selected Color
A UIButton has several "states," such as Normal, Selected, Highlighted, and Disabled. In each of these states, you can set the button's title, font, text color, background image, etc. What you're looking to do is set the button's background color to white for the Normal state, and gray for the Highlighted state, which unfortunately isn't possible, but there are plenty of SO answers about how to achieve the same effect.
Alternatively, you can set background images by a button's state, so you can set a pure-white background image for the Normal state and a gray background image for the Highlighted state.

Button Hiding the text in iOS6

I have a text box which has a popover. Also placed a button on top of the text box to make it clickable so that when button is clicked the popover is opened and any item selected will be shown in the text box. This is working fine in iOS7 but in iOS 6 i am able to select the item in popover but the button is hiding the text. Tried setting colour of button but didn't work.
Please help.
If you set the type of the button to "Custom", and you don't set an Image or a Background Image, the button will be invisible on versions prior to iOS7 too.
If you create the button programmatically:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
If you change it on your interface:
Instead of using button, you can open popover by UITextbox itself. Just place the button's IBAction code in textbox's IBAction with EditDidBegin Event.
Set UIbutton's buttontyoe to UIButtonTypeCustom for iOS 6

uitoolbar with icons/text similar to uitabbar

Ideally I want to use a UIToolbar but I want the icons at the bottom to appear as they would in a UITabBar meaning with icon for default and highlighted states and title beneath. I know I can drag a UIButton onto the toolbar and it will create a UIButton inside of a UIBarButtonItem, but I can't seem to manipulate the UIButton to show a title beneath? The other problem I'm having is when I set the alignment of the button in IB (in the Control section) it only changes the alignment for the default state not the highlighted state. Can anyone give me some pointers here that would be great thanks!
rc
Putting the UIButton inside a UIBarButtonItem is the best way I've found to do it. Just set the text for the button and it should show up fine. When manipulating the positioning, remember you're manipulating the position of the UIBarButtonItem and not the UIButton. Hope that helps!

How to have a "Back button style" in the UINavigatorBar / Button

I have a UINavigatorBar and dropped a button to the left top corner in the Interface Builder.
Simple question:
The Button is round, how I can set the button to a "back-style" button?
(I mean, that the left side of the button is not round, it should be a arrow).
I just put together a simple UIViewController subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear/willDisappear logic to animate the back button the way the UINavigationController does while using the leftBarButtonItem property. You'd just have to swap out the back-button PNG and change your colors in a subclass.
https://github.com/typeoneerror/BBCustomBackButtonViewController
If you want the back button to go back to the last view in the hierarchy, just leave the button off of the top left corner, and it should show up automatically.
Otherwise, you may need to subclass UIBarButtonItem.
I think if you want to do this with a UINavigationBar that does not work in conjunction with a UINavigationController you need to create a custom view for the button that is shaped like the back button.

Resources