How to bring all desired UI Interface objects and views to the front? - ios

I have a background image for the view controller and two labels. The two labels are not showing up because they are behind the imageview. When I go to editor->arrange the send to front option is not available for the labels. And when I check on the layout debugger I can see the labels are behind the imageview. Is there another way to bring to the labels in front?

Assuming you are using IB, you can move things to the front/back of one another by rearranging them in the left panel. The first item in the list will lie behind every other item. So in this case your list of subviews should go:
1. Image
2. Label
3. Label
This will result in the labels lying one top of the image.

Related

How to hide view graphically while maintaining presence in stack view?

I currently have a stack view that is horizontal, fill, fill equally. Inside, there are 3 generic views with different coloured backgrounds.
My current problem is that, when I set one of the views inside to hidden=true, the other two views immediately expands to fill the void. I don't want this. All I want is for the space to remain blank and the target view to be "invisible" both graphically and to UI input events.
Instead of setting isHidden=true you could set view.alpha = 0 to make it invisible and also view.isUserInteractionEnabled=false to disable UI input events.
*As #robmayoff pointed out below the isUserInteractionEnabled=false is not actually required.
As I can see in your screenshot, you are using the constraints. So, when the element hides, collapses and the other expand.
Use 'opaque' flag to make it invisible.

UIButton with background image and title using auto layout

I currently face a problem when using UIButton. I have the background image designed by others like this:
background image
and I need to place the title for the button right after the white vertical bar in the background image. I tried to set left edge for the content but since I used auto layout, the frame will be different with different screen size(3.5", 4.7"...).
Is there a way to put text in the position related to background I want with auto layout.
Thanks
I personally would split the left side of the background image from the right side. This way you can have two UIButtons next to each other with horizontal space constraint of 0. The right side of the button will have to be placed inside a UIImageView so you can set the image as a property of the view rather that the button's background. You don't have to do this of course, but I prefer this solution as it is easier to manage across different screen sizes.
Here is a visual representation of what I explained above:
Separated Views for Single UIButton
You will then need to route the touch events of both buttons to run the same method or function, just so that both the right side and the left are clickable.
Note: I'm not sure exactly what you had in mind for the highlighting of the button, but this will have to be tested and adapted to get the desired effect.

moving image behind label

I have an image on my view, which I add programmatically & and not through storyboards. The image gets animated to move up the screen. At one point it crosses paths with several buttons and labels, which contain important text that gets blocked by the image passing over them. I want the image to move under the labels and buttons so that the text remains visible. Based on this answer IPhone Interface Builder: Z-Index, Z-order of a button, image, ui element, etc?, I tried to use editor => arrange => sendToBack/sendToFront, however, I don't think this is having any effect because the image doesn't appear in the tree of elements in the storyboard. As noted, it gets added programmatically at a certain time. Is there a way to do this?
I believe you can use [view insertSubview:imageView atIndex:0] which will place it behind all other subviews. Depending on what other subviews you have, you may need to increase the index as it controls what is placed over what in the view (lower index will go behind higher index)
As in answer to this question: Difference between addSubview and insertSubview in UIView class
If you're using addSubview:, your view will be placed on top. To control it's depth use either insertSubview:atIndex: (at exact place from bottom) or insertSubview:aboveSubview: or insertSubview:belowSubview: (which places new view above/below another known object in view hierarchy).

UIViewController with UITableView and TextField storyboard placement

This might be a simple question but using storyboard I can't seem to position my table, a message field and a button correctly. In the picture below, if it's positioned that way, only then do I get to see the text field and button at the bottom of the screen and the table view takes up the rest of the screen. If I drag the text field and button to the bottom and resize the table, the text field and button disappear and the table is cut off. Why is that? Is there a solution to this without doing it programmatically?
Easy solution is to remove all constraints then position them where you want them.
You'll find you get different effect when try to reposition items depending where you drag from for example double tap an item and nudge it with arrow keys or grab the middle to move it resizing via the corners.
But in my opinion it's easier remove all constraints from the view and then set them as you go.
Also you might want to consider using a container view for the table view and have a separate UItableViewController that way you can easily separate out that the tableview logic from the other ViewController. It will help stop things getting a little messy later on as project grows.

Positioning items in overlapping UIViews in xib file

Let's say that I have a xib with a stack of UIViews on top of each other:
The bottom UIView(A) with a UIButton on it and when the button is pressed,
this layer is hidden and the next one is shown and put on top.
The next UIView(B) contains a clock counting down from 5 to 0
and when 0 is reached this UIView is hidden and the one described above is
moved to front and shown instead.
So just to make it more clear:
the composition of the xib:
A B
--Z direction-->
update: screenshot attached at the bottom of page.
So to my problem:
When (re)positioning the button or the clock using mouse in Xcode they tend to stick to the wrong
UIView. The more the Objects and "stacked" UIViews the greater the problem.
The Question:
Is there any way to, as with the layer "eye" in photoshop, isolate the UIViews and work on them one by one?
Observe!
I am aware that there are o there ways of achieving this swapping between view BUT this is not the issue. The real problem here is to actually position the button and the clock in the Xcode wysiwyg editor with the least hassle.
Observe!
-------- Added for clarification --------
Screenshot
I would like to isolate the views visually so when working on one of them, all the others are hidden and not open for interaction.
You can drag the second view (B) out of the main view hierarchy and place it below it (on the same level of the main view). That way you'll be able to edit each view separately.
Then you connect that view (B) to an outlet in your viewcontoller inorder to be able to add it to your main view during runtime...just set the frame and add it as a sub view.

Resources