add background image in iphone using IB - iphone

I want to add a background image for some labels in my custom view. How do I add the same? If I use UIImageView, it comes as foreground image.

Double click the specific imageview in IB, then select Layout from the top menu, and click send to back. Or do the same with the label but select bring to front :)

It's easy to control visibility in IB, just view the .xib file in list mode. Items listed farther down in the list appear on top of elements above them in the list. So to place a background image under a label, drag the UIImageView into the view, and drag it to be above the labels in the view list. Like this:

You should add that labels as subviews for that image view.

Related

Adding UIButton to UIImageView within UIScrollView on Swift

I am writing an application for an event my organization is hosting using Swift. I have an image with the floor layout and want to add buttons to select locations (such as bathrooms, entrances, exits, emergency sections, etc) so that people can click them and information about the location pops up.
I currently have an imageview with the floor layout within a scrollview to allow the user to zoom in and out of the image. When I try to add buttons to the scrollview they don't stay relative to the image when zooming in and out, nor do their size change. I have tried adding constraints on to make the location stay the same when zooming in and out.
It also won't let me relocate the button on the storyboard to be a subview of the imageview. Looking up similar solutions says to add the button programmatically as a subview of the imageview but then it'd be really hard to put the 100+ buttons in the right location. Any suggestions as to how to go about this?
you have no other choice instead of adding by code.. because from code you can add as subview of image view , whereas Storyboard wont add buttons as subviews of imageView, but it will add buttons as subview of Scroll View

How to put my 2 existing buttons to the foreground, they are now behind an imageview

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.

adding icon to uisearchbar

Can I add an icon to the uisearch bar like this
Ya you can add the icon if you are talking about the image on left then just add a image and if you are talking about the image to the right. which i think is a search button then you can add a button and do your search code on it.
ok so what you have to do now is, i am assuming that you want to implement the search bar with icon on the toolbar. just add a UIButton and in the IB select the UIButton and go to attribute inspector and set the type to custom.
Now when you add the image to it(set the background property to the image you have selected)
By doing this you can easily resize your image.(means just resize the button, it will automatically resize your image too).
hope this will work.

iPhone Setting A Background Image

I want to use an image as a background for my application. I want the buttons to be over the image. How is this accomplished? Everytime I use image view it covers up the buttons.
The image view should cover your buttons unless you are placing it higher in the list of subviews. Make sure your image view subview is added first and the buttons (and all other views) will be displayed on top of it.
Are you doing this in Interface Builder or manually in code?
You could try using UIView's sendSubviewToBack method:
UIImageView view = / init view */;
// some additional code here
mainView.addSubview(view);
// add buttons, etc...
mainView.sendSubviewToBack(view);

UIBarButtonItem in middle of navbar?

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