I have a UIToolbar with a UIBarButtonItem that I created in Interface Builder. The UIBarButtonItem is a bordered button that contains a custom image.
The button takes up the entire length of the toolbar. I have tried using different images, changing the width of the button... I don't know what else to do. It stretches across the entire toolbar.
If I use one the provided "Identifiers" (camera, trash, compose...) the button appears a normal size.
How it looks in Interface Builder
How it looks when I run it on the iPhone
SOLUTION
After some more tinkering, here is what I found: if I create a new UIToolbar and add custom image to the UIBarButtonItem, it works fine - but as soon as I connect the UIBarButtonItem to an IBOutlet, it goes large. I had to then specify the UIBarButtonItem's width in the code, via the IBOutlet.
Try adding a UIBarButtonSystemItemFlexibleSpace on the right of the camera bordered item.
I'm not an expert, but I think it might have to do with how the frame is defined in the "sizing inspector", could you maybe show a screenshot of the settings?
Related
The question is in the title.
There must be a simpel way to do this I guess?
There is an imageview on the screen, there doesn't have to be any interaction with it.
On the imageview I want 2 small buttons left and right but the buttons were created (and the code is written) before the imageview. How do I set this imageview to the background? :)
[self.view sendSubviewToBack:yourImageView];
You can add buttons as subview of imageview.
you can write below code for that:
[imageView addSubview:button1];
[imageView addSubview:button2];
So buttons will be appear in foreground.
When looking at your xib or stoyboard (where you can see the layout), you can use the View Controller scene which is a list of all of the objects, views etc on your Apps layout.
You can click and drag the UI image view so its above the buttons in the list. I'm guessing it's just defaulted to being on top of the buttons.
In your storyboard, choose your viewController by clicking on it. On left side you can see hierarchy like left side view in this image. Check if your imageView is below, in hierarchy, to your 2 buttons. If it is, then drag the imageView and move it above both the buttons.
Concept : The view that is below in hierarchy is visible on top of all the views above it.
I am trying to add an image for my UIBarButtonItem from the xib file itself. However, I am getting a grey coloured button which is of the same size and shape as that of my image. How can I display the image correctly and directly from my xib file itself without going into the writing of code manually ?? The button is present on a toolbar. Thanks and Regards.
Use UIButton beside of barButtonItem. It will automatically make a barButton and a Button inside of that.
then you need to change batButtonItem text to "" and change the Image of UIButton
as I tested it will work and show your pic beside of barButtonItem
I have a simple view-based app from that template. It has nothing else in there, only one UIButton.
When the device rotates, I want that button to be re-layoutet in such a way that it fits the width of the screen automatically. It has a margin of 20 points left and right, which should always remain the same.
I am not sure what template you are referring to. But if you are adding the UIButton in Interface Builder, take a look at the inspector. What you would need to do is to make sure your UIButton autosizing struts and springs are properly set. There is a preview button that will show you how the button will be autosized if the view changes.
When a new view controller is pushed onto the navigation stack, there is standard support for a back button with the title of the previous view controller. This button "points" to the left rather than having a rounded rectanglar shape.
Is there a standard way to create a UIBarButtonItem that "points" to the right? This button would be used as the rightBarButtonItem.
Using the Three20 library you can do it easily without creating an image yourself (and it will size up correctly depending on your text):
This screenshot comes from the example application that comes with Three20.
You could use one of the PNG files floating around with iPhone UI widgets (example). Take the left-pointing button and flip it horizontally in Photoshop or another image editing tool to make it point right-wards.
Then insert a UIButton into the rightBarButtonItem view, using the horizontally-flipped widget as its image property.
I have created a flexible navigation bar in my app that will show custom buttons on the left, right, and in the middle. So far I have got working:
Right/Left/Middle - Custom Image and/or Text
Right/Left - Normal looking button with custom Image in it
Right/Left - Normal looking button with custom Text in it
By 'normal looking' I mean the default UIBarButtonItemStyle- just a nice shiny button.
My question is, how can I achieve the same look in the MIDDLE of the nav bar? I can do custom/text images by just creating a custom UIButton, and on the right / left I create a UIBarButtonItem from it, but in the middle I just add the UIButton view as a subview of the navbar.
I can't add a UIBarButtonItem to the navbar as a subview, and any UIButton I create doesn't look like a UIBarButtonItem.
The only workaround I can think of is to use a stretchable custom image that I steal from a screenshot. I'd rather avoid doing it this way. Am I missing something?
*********** UPDATE **************
The open source library Three20 will allow you to create UIButtons that look like UIBarButtonItems. Then you can add them to the bar view either by placing manually as a subview or by setting the title view.
I never understood why they didn't make UIBarButtonItems derive from UIViews (or even better, UIButtons) so they could be used elsewhere.
Sounds like you're on the right track, but need better artwork :-) You can get a large number of iPhone UI components in a Photoshop .PSD file from here. They have pre-rendered bar buttons which you can use as a base for a standard UIButton image. If you have Photoshop (or a decent drawing program) you can stretch the buttons from the middle to fit your size without getting the corners distorted. Just add the label and you should be good to go.
Put a flexible region on the left and right, they will offset each other causing anything between them to be centered