Custom UIButton showing border on iPad - ipad

I have four custom UIButtons sitting in front of a UIImageView, but for some reason on the iPad it is showing a white border around them. Essentially it's a UIImageView with a black gradient with four buttons on it. Each button is the height of the image view and they show a white line on each side. Is there a way to get rid of it?
The view was created on whatever XCode 4's version of Interface Builder is called.

I got this when I created the button in code as follows:
[UIButton buttonWithType:UIButtonTypeRoundedRect]
Which seemed to work fine on iPhone but on iPad I needed as follows:
[UIButton buttonWithType:UIButtonTypeCustom]

Related

iOS - how to change button image without resizing and repositioning the button view

I currently have a view containing 2 buttons - The view size is 320px wide and 52px tall.
Each button is 160px wide and 52px tall, and they stand one next to each other covering the whole view. Each button has a 160X52 image associated to them. The following behavior is happening:
when rendering the view I can see a padding rendering of the two buttons - I gave the background view a white color and can see a white line around each button. How can I have this removed?
second and most important - when clicking on one button I am having the image replaced with another one 160px wide but 62px tall. When rendering the view i see the Image resized instead of overflowing outside of the view. When checking the bounds and center properties of the button however, they have not changed.
I am not a view designer expert and I definitely have to do a lot more reading on how the rendering engine works, but if anybody can drop a couple of hints of what to look at to get me started it would be very helpful.
Tanks a lot
That's the code for a butto;
UIButton *firstButton = [[UIButton alloc] initWithFrame:CGRectMake(50.0, 50.0, 160.0, 52.0)];
[firstButton setBackgroundImage:[UIImage imageNamed:#"backGroundview"] forState:UIControlStateNormal];
[self.view addSubview:firstButton];
And that's 2 images of how the buttton looks when pressed. Are you sure you don't have any autolayout rules or a different image for the button? Instead of using "setBackgroundImage" you use setImage it will resize the button to the image size.

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"]]

Creating a custom UINavigationbar for iPad in iOS 5 with ARC

I am creating an iPad application for ios 5 using arc and storyboard in xcode 4.3. I need to customize the UInavigationbar to make it broader than its usual size (almost double sized) and add to it some custom logos (images) and buttons. Can anyone pls point me in the correct direction on how this can be acheived? any third party libraries are also welcome if required.
Thanks in advance for your help on this one.
To start, you'll want to subclass UINavigationBar. While it is possible to change the height, the UINavigationBar background isn't going to play nicely, so you'll probably want to use your own background image.
Here's some information about resizing the navigation bar
Change the height of NavigationBar and UIBarButtonItem elements inside it in Cocoa Touch
iPhone - How set uinavigationbar height?
And another article on how to add the images and buttons as subviews.
http://www.iosdevnotes.com/2011/09/custom-uinavigationbars-techniques/
I don′t know how you would change the size of the UINavigation bar.
To add custom buttons you can outlet your navigationItem in the storyboard to the interface of your view controller. Then use setLeftBarButtonItems: and setRightBarButtonItems: to put multiple buttons you previously created.
To add custom black and white logos to the buttons you can use [navigationButtonItem setBackgroundImage: yourImage].
If you want your logos in color you can create a UIButton with the colored logo ([newButton setImage: yourImage]) and then init your navigation button item with : initWithCustomView: newButton.

Button image in navigation bar has different appearance. Why?

I'm trying to put a UIBarButtonItem with a custom image on a UINavigationBar. When I do however, the image doesn't look right. I want the button on the navigation bar to look like the one below it.
(This is a screenshot from the simulator, by the way, not Interface Builder)
I created the custom UIBarButtonItem by creating a UIButton, using the cog-wheel image as a background, and then simply dragging it to the the right bar button item place in Interface Builder. Seeing as creating a UIBarButtonItem programmatically with the aforementioned UIButton as its 'custom view' (-initWithCustomView) has the same result, I believe this is what is happening as well.
What I don't understand is why the button image lost its nice edges and color gradient when I added it to the navigation bar wrapped in a bar button item. Can anyone tell me?
Thanks in advance.
The image hasn't changed. It is the same. Its just that when put on different backgrounds, it is showing differently. You should consider increasing the contrast.

How can I create a custom UIToolbar like component in a UITableViewController?

I have a UITableViewController. I want a "toolbar-ish" component at the bottom.
I started by using a background image and a button. In interface builder, I added them to the bottom of the iPhone screen. The problem I ran into was that the background image and button scrolled with the table. I obviously need this fixed at the bottom.
Not finding too much direction online, I decided to customize a UIToolbar to look how I want since the position is fixed by default. In my initWithNibName for my UITableViewController, I have:
UIImage *shuffleButtonImage = [UIImage imageNamed:#"shuffle_button.png"];
NSArray* toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithImage:shuffleButtonImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(push:)],
nil];
[toolbarItems makeObjectsPerformSelector:#selector(release)];
self.toolbarItems = toolbarItems;
The problem I am running into now is that the "shuffleButtonImage" is not showing up properly. The shape of the button shows up fine but it is colored white and therefore does not look like the image.
Does anyone know why a "white image" would be showing instead of the actual image?
Also does it sound like a good idea to customize a UIToolbar or is there a simple way to ensure a fixed position "toolbar-ish" component.
To reiterate - my "toolbar-ish" component only needs to be one button at the button of my UITableView. The single button has a gradient color background that I create with an image.
From the description of the "image" parameter in the documentation for the initWithImage:style:target:action: method of the UIBarButtonItem class:
The images displayed on the bar are derived from this image. If this image is too large to fit on the bar, it is scaled to fit. Typically, the size of a toolbar and navigation bar image is 20 x 20 points. The alpha values in the source image are used to create the images—opaque values are ignored.
Basically, the image you provide is used as a mask to create an outline/shadow for the actual button image. I do not believe you can change this behavior for a UIBarButtonItem.
As an alternative, you can create a UIButton (with your color image) and then set it as the custom view for your UIBarButtonItem, as suggested here. If you go that route, setting the bounds of the UIButton to match the bounds of the UIBarButtonItem might also be necessary (see this discussion).
Your image may be showing up blank because it's not being found in your resources. Put a breakpoint after your definition of shuffleButtonImage and check it's not nil.

Resources