How to set a UIView to be of certain size? - uiview

Suppose i need to place a UIView of size 320 x 376 onto my Window?
How can i control this from the Interface Builder?
ANSWERED: Image below shows how to do it visually

Go into the size Inspector (In Xcode 4, it's Command-Option-5; the icon is a ruler). From there you can type in a size.

Related

Why does any UIView that I drag into a xib file turn into an iPhone XR?

This is a picture of a UIView in another UIView with View 2 nested in View 1. Note that I cannot change the size of view 1.
This is what happens when view 2 is dragged outside of view 1; it forcibly turns into an iPhone XR, again, with the width and height properties grayed out.
I would like for these views to just be normal UIViews that have the ability to have their width and height changed. Any ideas as to why this might be happening? Am I missing a setting or property that's causing this to happen?
You have the View as: option set to iPhone XR. To change that, click on View as... at the bottom and change it to a different device (preferrably to one without a notch, such as the iPhone 8).
Here's how to do that (click on the images to enlarge them):
To change the size of a top-level UIView, follow this guide.

Top level UIView in .xib file (in a "Universal" device project) defaults to 600w x 600h - can this be changed somehow?

Please see attached screenshot:
When creating a .xib file with only a UIView in it Width and Height settings default to 600 each, and are greyed out. Is there any way to adjust these numbers please? Thank you.
Context: I have a UITableViewCell that may feature one of a number of different UIViews embedded in it, on the fly, and these will only ever be of a set height (70 or 128).
In Attribute inspector you need to change the simulated Metrics size to Freeform. Then you can adjust the size of uiview.
In the Attribute inspector you have to change the size to freeform. Then in the size inspector you can change the width and height size.
Try following solution. You need to change size Inferred to freedom.

UIImageView sizing in AutoLayout + Size classes for all devices

I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.

Load UIView from XIB incorrect size

I'm new to iOS 8, I tried to load a UIView from XIB file with auto layout and size classes option are enabled. I use Inferred size XIB with default size is 600 x 600. But on the simulator the size of view is not fit screen size, it still be 600 x 600 and doesn't fit the screen size like this, it's much bigger than the screen on width:
But when I use View Controller widget, it has Resize of NIB option, and it work fine to fit the screen size. Can anybody suggest what should I do to resize UIView to fit screen size? Thank you very much, guys!
Update:
Here is how I call it:
And constraint I use:
You should use autolayout and set constraint. It is better choice if you need to support multiple device.
Try to figure out with these 3 images first. Then I am discussing one by one.
http://imgur.com/mE2dNm8
http://imgur.com/PVW6yrk
http://imgur.com/LLZkMgx

A white bar below my app after Xcode 5 upgrade

As iOS7 and xcode 5 is out, I am assuming we can talk about them. Today I upgraded to XCode 5 and suddenly on my mapView.xib I see a white bar below. I did not touch the xib file, what exactly is going on here and how I can fix it.
Don't worry. You'll have lots of fun re-adjusting your layouts. Some of the components dimensions changed drastically and probably you'll need to re-adjust windows and UIViews too.
This is because of structure of iOS 7, To resolve this issue select your background UIImageView in xib and apply following Autoresizing mask
After that create new imageSet with name "iOS7bgImg" and add device support [iPhone & iPhone 4-inch] and add respective images in a boxes with following resolutions.
320 * 480
640 * 960
640 * 1136
create a IBOutlet of backgroundImage view
Now check programmatically
if(iOS 7)
{
[Setup new image in your background]
}
That's it solve.
Open the xib and set the frame of the view of this view controller to the screen frame. In iOS7 the status bar is translucent and your view also is behind it. Therefore your view has to be 20 px taller to fill the screen.

Resources