UIButton .selected doesn't cover whole width of button? - ios

Edit: Here is the screenshot:
The button on the right is selected. I'd like the color to fill the entire button.
The buttons are created on storyboard with widths pinned. I simply toggle selected/not selected with
button.selected = YES;
I have not found any similar questions about adjusting the width of the part that is selected, and I haven't been able to figure out any solutions. Any ideas?

Make sure your UIButton's type is "Custom", not "System".

Related

Disable the background of a uibutton

I have a circular custom menu with several buttons (with image and text). To not cut title, I had to unlarge button size, but the background of few buttons overlay partially the image or title of other button. That why I'd like to disable the background of buttons, or make image and/title only active.
How can I do?
Thanks
As others have mentioned, you could change the background color quite easily with the following:
Swift 3.0
buttonName.backgroundColor = UIColor.clear
Swift 2.2 and prior
buttonName.backgroundColor = UIColor.clearColor()
Are your buttons overlapping because they're crowded? If so then from a design point of view I'd look at redesigning that aspect. Users may be misclicking if you have a number of overlapping crowded buttons.
I let backgroungColor to gray just to show you. I create buttons with a specific width in order the title is well writen. Maybe I can calculate the exact width of the title and attribute it to the button. That would solve partially the problem.

iOS/Swift: Dynamically Resize a Toolbar

I'm trying to make an app with a toolbar that can be resized. Basically, the toolbar can alternate between being at the bottom of the view and being at the top. When a button is pressed, it switches from one to the other. The problem is that when it is at the top, I want the size of the toolbar to expand to accommodate the status bar, but I don't know how to do this.
I've seen some solutions for changing the toolbar size but they all seem static and not something that can be changed with the tap of a button. Any suggestions on how to do this? Perhaps a different solution altogether?
You can use a normal UIView and customize it so it looks like a UIToolbar, then just set constraints using AutoLayout and animate the height-constraint.

Image on UIButton

I have an ImageView with a picture and a button centered within it. On the button I have a different UIImage and the background on the button is white. In Attributes Inspector I have selected the UIImage for the button and made the button custom but still I have white background on the button.
I want the background on the button to be the same as the picture on the ImageView. I thought it was enough to change the button to custom. I am using Xcode 5.0.2, is there anyone that could help me with this. This is what my ImageView + button looks like now:
And these are the settings for the button:
If you're asking how to make background for the button clear, from within the Attributes Inspector scroll down to the View section and change the background to Clear Color from the dropdown menu.
Also make sure your .png has a transparent background. If you've already set the background to Clear Color the issue could simply be that your .png has a white background rather than a clear one.
try
[button setBackgroundImage:[UIImage imageNamed:#"name" forState:UIControlStateNormal]
Add image that you use for ImageView to Background properties of your button.
The following should do:
yourButton.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"yourImage"]]

How to get highlight effect from an invisible button over an imageview

I put a button over my imageview. So it is a custom button and have nothing inside of it. It is invisible. I cant change my structure so I have to put that invisible buttons on my imageview.
My question is is it possible also to having highlight effect of the button? Because when I press the button everything is ok. It is working like a charm. But as expected there is no highlight effect. How can I have it?
Try setting showsTouchWhenHighlighted of UIButton to YES. I hope this was what you were looking for.
You set the highlighted image for button by below code.
[sender setImage:HIGHLIGHT_IMAGE forState:UIControlStateHighlighted];
I ended up by using a black over image with %50 opacity.

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!

Resources