UIPopoverController presentPopoverFromBarButtonItem:... Off-Center - ios

I'm presenting a popover from a bar button item, and the arrow of the popover is not centred horizontally beneath the item:
I'd like to budge that over to the left by a few pixels.
It doesn't occur on all UIBarButtonItem instances, just once I create with custom images. So for instance, the rightmost button item has a perfectly centred arrow and it's instantiated using a system item:
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(shareButtonWasPressed:)]
But if I use a custom image,
[[UIBarButtonItem alloc] initWithImage:slideshowImage style:UIBarButtonItemStylePlain target:self action:#selector(slideshowButtonWasPressed:)]
... it's off-centre. I've tried adjusting the imageInsets of the button item, but it stretches the image. Any suggestions?

Turns out the easiest way to do this is implement your own subclass of UIPopoverBackgroundView and use it to adjust where it displays the arrow. This involves a lot of custom drawing code and I couldn't have done it without a designer, but we wanted a custom background anyway, so it was worth it.
Still no idea how I'd fix this without what's arguable a work around.

Related

UIBarButtonItem Moves From Side to Center

I have a UIToolbar with UIBarButtonItem on left and right.
First time go to screen:
Subsequent:
Anyone knows why UIBarButtonItem goes from side to center? For sure, there is no code inside my application to move UIBarButtonItem.
Note
Using code or load it from XIB both have same result.

UIBarButtons styled with System Items, disappear after rotation

In our app the initial ViewController is embedded in a regular Navigation Controller. We have two UIBarButtons, located in the upper right of the navigationbar. One of the buttons is styled with a custom image and the other one with the camera icon from the provided System Items.
Here is the problem:
When the app starts in portrait, both bar buttons are visible. After rotating the device to landscape, the UIBarButton with the camera symbol disappears and no longer shows up when rotating back to portrait again.
I have no outlets to neither the navigationbar nor the UIBarButtons, no adjustments in code are made whatsoever.
The button that disappears after rotation still exists in the navigationbar, if you tap where it is supposed to be shown, the action is triggered. It seems to only be the image that is removed for some reason. And only if the button is styled with any of the System Items.
Can anyone think of a reason why this problem occurs?
Ok, this problem was related to appearance proxy code that I had in my appDelegate:
[[UITextField appearance] setTintColor:[UIColor darkGrayColor]];
[[UITextView appearance] setTintColor:[UIColor darkGrayColor]];
Apparently these two statements affect the behaviour of the barbutton appearance. I cannot see why, but I am sure that there is a good reason.
Getting rid of these two statements in the appDelegate solved the problem.

UIToolBar button not positioning correctly after increasing height

Well the problem is well understood in the image below , so I'm trying to increase height of the UIToolBar but the buttons aren't aligning correctly to the toolbar. Is there any solution for it?
This is because the button will start their drawing from the top, so it will move lower once you start increasing the height of the button, since the text will be in the middle.
I am pretty sure there is no way to solve this.
EDIT:
I found a way you can set the text:
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 5.0f) forBarMetrics:UIBarMetricsDefault];
Use the offset to change the location for the text
The little solution i found is to use UIButton instead of UIBarButton.
UIButton will align correctly to the UIToolBar(with/without changed height).

UINavigationBar right button too tall

I'm using custom images for UINavigationBars and UIToolbars. The problem i'm having is on 1 of my views that uses a UINavigationBar, the right button appears too tall
On the views that use a UIToolbar (modal views so no Nav bar) they look fine
What could be causing the button to be too large? I've tried adding the button in IB and also using code. Then set the image like this
UIImage *barButton = [[UIImage imageNamed:#"ButtonBlue"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 8, 6, 8)];
[self.connectButton setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Thanks
Create a smaller button. You can do this in Preview - resize it. Make sure you have #2x sizes too. T cannot recall the recommended size for theses images - it's something like 30 points or so (search and you'll find it for sure).

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