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

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.

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 can I add a UIScrollView to a View in an iOS app?

I have built a small iOS 6 app that uses a single view. However, I would like to add some more functionality and therefore need more space. I figured that the best way to do this is to add a UIScrollView.
How can I add such a UIScrollView to my View? Do I have to delete all my buttons, labels, etc. in my View, then add a UIScrollView and then put all those buttons, labels, etc. in that UIScrollView? I think that this would work but is there an easier way to do this? (Maybe without deleting all the content in my view)
Yes you can add a view to UIScrollView without deleting buttons, labels, etc..
To add a scroll view to existing view:
Draw and drop the UIScroll View to the existing View
Select all controls in the View like Buttons, Label etc.; except UIScroll View
Drag all the selected component into UIScroll View
Let me know if you have any doubt.
Add all views on scroll view like:
[scrollview addSubView:button];
And finally add this scrollview to main view:
[self.view addSubView:scrollview];
I think this will be helpfull. :)
programmatically you have to
[scrollview addSubView:button];
instead of [self.view addSubView:button];
In storyboard or xib you can drag and drop the button onto the scrollview.
Hope this helps a little bit.

Fix UIButton on top of UIScrollView

I'm trying to figure out how to overlay a UIButton on top of a UIScrollView. Basically the user would be able to use the scrollview normally. But a button in the top right of the scrollview would remain in a fixed position. Any thoughts?
Don't add the UIButton as a subView of the UIScrollView, but instead of "self.view"
In the InterfaceBuilder there will be a Hierarchal list of items you put in your view, drag the button from being a view belonging to the scrollView to belonging to the view containing the subview.
Your view hierarchy will look like the following
mainView
|
----Button
|
----ScrollView
Instead of
mainView
|
----ScrollView
|
----Button
basically It means both your button and your ScrollView will both be subViews of the exact same mainView. If your scrollView is the mainView put an empty UIView above the scrollView and insert the UIButton & UIScrollView into that
IB is a little finicky when dropping new views directly on the 'fake' interface. What you will need to do is go over to the left in the list of views and select your button view. Now drag it up to below the 'self.view' or whatever is your top level view.
YOu should notice as you raise it up and down in the list that a light blue line will appear. The width corresponds to 'subview' or 'parent' view connection. Play with it a bit to see the difference.
When you feel comfortable, you should be able to place the Button in the 'self.view', not as a subview of the scroll view. Additionally, if you want it to appear on TOP (physical 'Z level') you will need it to be below the scroll view in the list. ( this points out a subtle problem with CStreet's solution)

xCode 4.2 iOS5 interfaceBuilder cannot tap on a button that is laid out in the IB

I've ran into a weird issue lately:
I have a 320 x640 UIView within a UIScrollView. I've manually positioned buttons throughout the view and assigned actions to them. One of the buttons has a center at [x,y]: [287,440]. The button is 60x60.
I can tap all other buttons and controls located as low as Y = 353.
I see that the button is located on the same level as all of my other buttons, within the same view as them.
What could be causing my button to be completely untappable? I have another controller, which is also "tall", and there buttons located "off screen" are tappable. [If I move the button up to the level of other buttons, it works as expected.]
Here's the scroll view code:
self.scrollView.contentSize=CGSizeMake(320, 640);
Something is covering it. Try looping over all subviews and printing origin.y relative to scrollview origin.y, and then height plus relative position. Do this in viewWillAppear. Be aware that autoresizing behavior can kick in right after viewDidLoad and fool you. That is what happened to me earlier. There will be an overlap somewhere.
Can post code example later from home if this doesn't get you through it.

iPhone UIButton Parent Frame Changing Touch Up Inside Event Issue

I have a UIButton within a UIView. The button is docked on the bottom of the view using the Autoresizing Masks. The button is working fine when the view initially loads and the IBAction is being called successfully.
Now when I resize the height of the parent view the button stays docked at the bottom of the view, however now only half of the button responds to the touch events. If I resize the parent view height a bit larger then the button completely doesn't respond anymore.
Any ideas why this would be occurring?
It sounds as if you've got another view, most likely a transparent one, that is resizing improperly and covering up part of the button.
It seems that I was moving the main view as the inner view height was changing. I guess if the UIButton is outside the bounds of the self.view then touches are not received.