Autolayout position reset - ios

I have a View and i have a an image view inside it and a another UiView and one or two more view in side the top level view. The problem is when i run my app in different screens iphone the image view resizes and i want the other view to change the their position to a little bit down. But only image view gets more space, but i don't want the other view to get more space but i want them to change their position.
Here i want the white view the Placeholder text and the the small picture view to change their position and go a bit down when the app runs on big screen iphone. Th rounded image view above the Mybutton gets more space when the screen resizes which is okay but the white view and other view remain at their same place. Just to add more information all these view are siblings of each other and i have fixed the the width and height of the white view, picture view and the placeholder text label
Any guidance please?

I think you have to start with the "movable" element and then add every "fixed" element.
I think you have to work with Center Y Alignment Contraint even if you have to create new view for it. The beginning could be :

Related

How to place any view below any other view which is getting it's position from code

I've created 4 subviews of white color & a yellow one as you can see in reference image I've shared below.
And I've programmatically changed the position of Tabbar from bottom to top just below to navigation bar as you can see in below image (When it is running in the simulator).
Now since I've constraints for that yellow view in image as follow
It is appearing just below to navigation bar but I want it to be displayed just below the Tabbar.
Since Tabbar is getting its position programmatically & other views (including yellow view) are getting their positions from the storyboard.
And since storyboard UIelements are get settled before any other UIelement which are coming from the program or at least get their position from programmatically.
What could be the best way to achieve what I want.
Please refer my storyboard as well to get more understanding. (Refer Below image)
I also want to fit all 5 subviews in the space between tabbar & bottom of the screen. I want to calculate 1/5th of that space & assign this height to each subview. I'd later reduce few pixels to separate them.
Why not add the height of the tab bar to the yellow view's top position? That way, you'd set the constraint something like:
Fajar.top = top + 44
If the tab bar is always visible, then that should work. But of course, if the tab bar only appears at times, you'd probably have to change that constraint programmatically depending on the change ...

How to make a tableview fill all the available space?

This is my first swift application, so apologize if it's very basic. I was unable to find it...
In my view, I've a Navigation on top (Navigation Controller) and It's using a TabBar Controller. I'd like to make the TableView fill the whole empty space no matter the size of the device nor orientation.
I set the property Content Mode to many different options, including Aspect Fill, but all the options can't cause any effect.
Any clue about it ?
First make your tableview completely fill the screen and then set the constraints to be in 0 margin from all sides, like in the image
use constraints for display full table view on empty space.enter image description here
Click on pin icon from bottom side of Xcode.
Select all for four(up,down,left,right) constraints and set 0 value for all.
after then click on add constraints button and refresh frame(click on right side button of Pin button and select Update Frame).

Buttons going below screen in landscape mode

I am learning iphone app development and I am using swift. I took the lynda tutorial and I have created a very basic UI which is View Controller > View .
In the View I added a segmented control, two buttons(horizontal, facing each other), three labels, one textarea and two other buttons(horizontal, facing each other).
So I have these UIcomponents arranged vertically and I used 'Reset to suggested constraints' and made all the buttons equal width and equal height and everything is fine in potrait mode but as soon as I go to landscape mode the last two buttons disappear, if I add a constraint from bottom edges the whole UI gets messed up i.e. only one label and part of an upper button appears.
What should I do to make all the UI components visible both in potrait and landscape mode?
There are many ways to go about this. I've set up a github project to show you one way to achieve it.
Short resume of what I did manually without the help of the Interface Builder:
I've pinned the segmented control to the left, top and right of the parent view
The red button below has a vertical constraint to the segmented control and a leading constraint to the parent view. It also als a horizontal space constraint to the green button
The green button has a trailing constraint to the parent view, top aligned to the red button and widths set to equal to the red button.
This setup ensures, that the segmented control is responsible for specifying the distance to the top of the parent view and the red button specifies the width of itself and the green button (test it, by changing the value of the horizontal space constraint)
I've turned the same principle upside down. So the views in the bottom are always pinned to the bottom. But as I said, there are many ways to achieve this. You could also create 3 container views for the elements in the top, center and bottom and pin those to the top, center and bottom.
The running app looks like this:
If you would like to display your content differently in landscape mode, it is possible (and most likely preferable) to create an alternate landscape interface.
Quoting the Apple developer's page on the subject:
"To support an alternate landscape interface, you must do the following:
Implement two view controller objects. One to present a portrait-only
interface, and the other to present a landscape-only interface.
Register for the UIDeviceOrientationDidChangeNotification notification.
In your handler method, present or dismiss the alternate view controller based on the current device orientation."
For more information about this, check out this apple developer page and scroll down to "creating an alternate landscape interface".
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html

Text View keeps resizing/resetting to zero size and coordinates

In my iOS application storyboard i have a few view controllers which contain one or more TextViews. Now, on almost everything i do within those views, like adding another button, or resizing a text box, those Text Views 'jump' back to the upper left corner and at the same time they get resized to 0,0.
Is this a bug, or can i do something about it?
I'm using Xcode 6.1

iOS : How to create a close button that sits on the edge of a UIView with rounded corners (using IB)?

Background:
I am working on an iPad app that will pop a custom view when the user clicks on an image.
I want the view to have rounded corners and a close button ( red x in a circle ) that sits on right top edge.
The button in half inside and half outside the view.... Take a look at the Kayak or Zynga Poker apps to see what I am talking about.
Question : If I create the view programmatically and add the button, it works.
However, I really want to user a nib to create the view so I can design the view correctly. So when I call self.layer.maskToBounds = YES on the view ( to create the rounded corners with a radius of 25 ), it clips my button ( since its half in and half out ). How do I retain my button without it getting clipped and still have rounded corners ?
Sounds to me like you are using a view and a button. What you might try is using a third container view (with clear background) in which you place your original view and your button. The button will need to be on top of the view, so to speak, so it is not obscured by your view. But that should allow you to have properly rounded corners on your view (not the container view) and have your button fully visible.
Some settings, such as maskToBounds, cornerRadius, aren't available in IB. You can create the entire view using a NIB except it won't have rounded corners in IB and in viewDidLoad you set just those properties that couldn't be set in IB.

Resources