scale subviews to fit inside uiview - ios

What I'm trying to do is very simple...i think. I want to make sure all the subviews within a view in my view controller are scaled to fit. Inside it.
My view controller has a menuview (subclass of uiview). Within that there are uiimage views, labels, and a button. The MenuView class I created has a nib file with a uiimage view that I want to scale to the size of the menuview depending on the device used. I'm not sure if the menuview is not staying constrained to the screen or if the uiiimage isn't, but when i run my program the menu runs off the screen.
Question:
- Can I force this (uiview and/or uiimageview) to stay on the screen using storyboard (programmatically is ok, but would prefer to try with storyboard)?
If anyone can point me to a good introduction to auto layout view and understanding the mainstoryboard that'd also be appreciate because it's insanely frustrating.
Screenshot: in the image below you can see I have a letter image that I want within the limits of the screen.

Related

Everything moving up ion view when UIImage doesn't exist

I have designed a UIView where there's an UIImage at the top and under it there's an UILabel. Both of them are populated by JSON and sometimes there won't be an image to load so I want that when this happen, the rest of the stuff in my UIViewController move up so that the space in the picture doesn't exist.
And, actually my image isn't appearing anyway, this is my code:
self.imagen.kf_setImageWithURL(NSURL(string: "http://elpenitente.playcofrade.com/img/upload/\(idfoto)")!)
If you have a scroll view on your screen: Unchecking adjust scroll view insets in the inspector may solve your issue.
If not you probably have size constraints that your not noticing. Check the different screen configurations.

AutoLayout Not Working For 5.5" iPhone

In my app, I have a screen that needs privacy, so when you first open it, it will check if you have logged in with the password. If not, it adds another view on top of the SuperView until that password is entered. I use XIB file for this. The main View of the screen is a tableview, and I drug on another UIView to use as the Password screen. However, despite AutoLayout, the Password view is only taking up the dimensions of 4.7" phone, meaning you can see behind it on the edges. I made sure AutoLayout is enabled, and on the background image, which is the gradient, I added 4 constraints, one for each side, set to 0, so that it would always cover the view behind it, and then set the UILabel to be aligned horizontally in container. What am I doing wrong? This works PERFECTLY in a different view and XIB within the same app, and I even copied the view straight over, but it is still messing up on this one class.
Code to load this is (password is the UIView declared in the header as IBOutlet UIView *password:
[self.navigationController.view addSubview:password];
The correct solution is to use a view controller to manage the curtain view, and either push that view controller onto the navigation controller's stack, or present it from the navigation controller or the tab bar controller.
There may be 2 possible reason
you may not applied constraint on your xib.
you have applied constraint on it but when you are initialising your xib you are providing fix frame.
it would better if your share your code how you are doing it ?

Making UIContainerView as wide as device screen

I can't seem to correctly reason about this problem so I was hoping someone could give me some tips to guide me along.
So I have 4 UIContainerView's WITHIN a UIScrollView.
As the User swipes, the Containers display 4 individual UIViewControllers.
What I want is, through autolayout, to specify that each UIContainerView must take up the device screen's width. So as a user scrolls, one UIViewController is shown at a time on the entire screen
The problems I am running into:
1. Can't make a IBOutlet from UIContainerView .. not sure why
2. No way in autolayout to specify "device screen width" within a UIScrollView
Any help would be appreciated!
Your UIScrollView must be contained inside a UIViewController nib. Make constraints from your container view for equal widths to your view controller's view in Interface builder, and then place all container views next to each other using AL.

Mass auto layout option for 40 viewcontrollers?

I designed about 40 view controllers using a 5.5 inch storyboard layout. After all of that I tested it on the iPhone 4S...big mistake. everything is jumbled together being for a larger screen size. I was able to fix one view controller up using Size Classes. I am wondering if there is any way I can adjust all 40 at the same time, or at least avoid doing this for every single one. It is really frustrating finding this out now. Thanks!
This is a relatively complicated issue you are attempting to solve, but I have two potential solutions. Both suggestions are based on moving your current interface into containing UIScrollView instances
If you are using storyboards, then for each of your view controller scenes, put a UIScrollView as a descendent of the view controller's view. From there, provided your subviews are contained within other views (like a container view for a set of buttons), you can move those into your scroll view. You will have to setup constraints to define the size of the scroll view's content, but this will allow the size of the device to have a smaller impact on the interface as you will get scrolling as needed.
If you are using nib files (.xib) then it is essentially the same thing, but easier. In this case, move a UIScrollView onto the canvas, but not as a subview of the default view. Once that is out there, move the original view to be a subview of the scroll view and set constraints to be 0 from the subview to the scroll view. Finally, right click drag from the File's Owner icon to the scroll view and set that as the view outlet.
Hopefully one of these will help you.

Can't adjust autoresizing mask for viewController

I'm trying to adjust my app to iPhone 5, but I ran into some difficulties.
The header of the ContainerViewController (always stays on top)
The ContainerViewController that holds the other ViewControllers
SidebarViewController
ContentViewController
So, the container contains the header, sidebar and content views. Inside content view I have UINavigationController. My problem is when I use iPhone 5 it changes all of the application looks, even when I use Autoresizing Mask, it looks bad and not on the correct position, I think that it's maybe because of the container header that I created.
I set it like this:
And this is an example of the view that holds UIScrollView and UIImageView as background: (pay attention to the bottom of the UIScrollView and the UIImageView, it pushes them outside of the view.
iPhone 4:
iPhone 5:
This is the first time i'm using Autoresizing mask, so please be patient with me. Thanks in advance!
Am not going to answer this deep down. You have set the auto resizing wrong.
Here are things that will work. To deal with iPhone5 you just need UIViewAutoresizingFlexibleHeight as autoresizingMask
If you want to know properly about Auto-resizing read through this
For Container
For Header
For Content
For Side Bar

Resources