How to change the width of the UITablewViewCell with autolayout? - ios

In one of my tableview i'm using a custom view created with a XIB file.
The tableview is correctly resized with autolayout, but the width of the cell is fixed.
In particular i saw that the ContentView is fixed to 320 px (the size used on the xib file).
Is there a way to use autolayout to change this value?

Sounds like you haven't set any constraints in your custom cells. The cell itself isn't the problem I guess, usually the container view is. So lets say you created the cell to fit the iPhone and it looks cut off on iPad, it most certainly because the UILabel or UITextView or any other element in the XIB isn't configured to stretch according to its constraints.
There's this beautiful tutorial by ray wenderlich, if you wanna learn more about auto-layout and how constraints secure that your app looks good on any device
If you need further help, just let me know!

Related

Change size of a UIImageView in storyboard

I have a UIImageView and several UIViews in a UIViewController on my storyboard, but on a iPhone 4s, part of my UIImageView is located on another view.
EDIT:
I want to reduce my UIImageView’s size and get about this result:
How can I accomplish this in the storyboard and not use any code?
my UIViewController in storyboard:
This can be achieved with auto-layout, which means no code. You need to adjust the constraints depending on the size of the screen. This is called size-class-specific layout. By default xCode uses size classes but only one. To add more classes you need to do this manually. This is not as technical as it sounds and is fairly easy. It is explained by Apple in the docs here: Auto Layout Guide: Size-Class-Specific Layout
I think Apple's Documentation explains constraints very well which will solve your problem without any code.
Basically all you do is:
Make sure your UIImageView is selected.
Press on the constraints button on the bottom of the storyboard's screen(looks like a square).
Constrain the view by selecting the pins on the sides of the box (at the top of the popup) and giving constraint values.
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/index.html

iOS: Resizing TableView depending on screen size

I'm trying to have a tableview resize depending on the screen size. The app is designed for iPhone 6, so it should basically shrink if the screen is smaller. I tried using constraints and pinning to superview, but it only seems to work for the height. I'm thinking I might have to resize the cells as well, but I'm not sure how to do it.
I know the question is very general, but I absolutely don't know the first thing about this.
Thanks for your help.
You need to use autolayout for both your tableview and your cells, otherwise ios will just try to guess the missing constraints (poorly). Make sure you set both horizontal and vertical constraints.
If you can disable autolayout and use AutoResizing, it might be easy.
After disabling the autolayout select your table in xib and go to Size inspector on Right Pane. In that set the auto resizing as follows
It can adjust the height and width automatically. No matter the size of screen is.
Additional: If you have excess of empty rows at the bottom hiding the size, you can remove it by the following code:
self.table.tableFooterView = UIView()

IOS different xibs for different screen sizes

I am new to IOS programming and would like to display a square image in a UITableViewCell, so size would be 320x320 or 375x375 for iphones 5 and 6 for instance.
Can this be done with a single xib file or two different XIB?
If it's 2 XIB, what is a good screen size test for registering the correct nib as a tableview cell?
You can use single XIB using AutoLayout and Adaptative Layout provided by the Size Classes : Apple Doc.
Size Classes allow you to deal with different sizes. [Regular] - [Compact]
You should found here what you are looking for.
You can do this in a single xib. Using autolayout, you have to add a constraint to specify that your cell's height should be the same as its width. This way, if the width changes your height is automatically updated.

Swift: UITableViewCell size to width of parent UITableView with autolayout enabled

I'm experimenting with autolayout and am running into trouble with UITableViewCell since they're created at runtime. My cells are loaded from a xib from the main ViewController. This xib has View mode set to Aspect Fill.
I've read about different ways to do this online and have yet to get any of them working. What's considered the best way to handle this?
It looks like your constraints aren't set properly, as the cell is shorter than the image's height.
Using AutoLayout and self-sizing cells is the easiest way to handle what you want to do. Once your constraints are setup properly for your custom cell, tableView:cellForRowAtIndexPath: can call dequeueReusableCellWithIdentifier:forIndexPath: and all the subview layout will be handled for you.
See the detailed walkthrough by smileyborg in his answer to Using Auto Layout in UITableView for dynamic cell layouts & variable row heights.
He also provides workarounds for the minor issue with the initial cell width being based on the storyboard cell, instead of the tableView width. I worked around it by setting the cell's initial width to the tableView's width, as Rasputin had suggested.

unable to get frame size of a Subview that I have put on UItableViewCell

I have been trying to get the frame of ImageView That I have put on UItableView Cell.
Situation:
I am using Story board. And on one of the viewController I have added the UITable programatically.
I separately created a XIB file of a UITableViewCell and on them I put some UIviews like Lable, ImageViews etc. Since my app is for all the devices including the iPad, I have used the Autolayout(which I have used First time). I used the autolayout and subviews are adjusting/changing their height & size according to the device perfectly, as I check on device.
Only problem is I need the the width of one of the SubViews of my UItableView cell. Inspite the view is growing and adjusting as I have made on XIB using the autolayout it Gives me Wrong width of the SubView. no matter on which device I run, It gives me the same width every time, the width it got on the XIB file.
Is there something I am missing regarding the Autolayouts or UItableView Cells?
Please let me know if some Information is missing in the Question
I have added the Image for reference. The UIimageView in middle

Resources