Custom UITableViewCell Leading Alignment to Right Detail Cell - ios

I am using a UITableView with static UITableViewCells. I am using custom cells and also right detail cells. I would like to get the UILabel within the custom cells to align with the UILabel within the right detail cells.
I checked within Interface Builder, and it shows the UILabel in the right detail cell to have the x origin to be 15. Within the custom UITableViewCell, I set the UILabel to have the same starting x origin. This works great on iPhones, but when I load the app on an iPad, they aren't aligned properly. The UILabel within the right detail cells appear to have a starting x origin of about 18.
Is there something I can do to ensure the UILabels have the same leading alignment within Interface Builder, or do I need to programmatically set constraints depending on the type of device?

Unfortunately I don't think there's an easy way to make constraints based on Apple's pre-made cells. You'll probably have to go with just programming the constraints manually, or another option is to make your own implementation of a right detail cell and make the constraints the same as your other custom cell.

Related

ios - UITableViewCell does not fill the entire width of the table

I think the cells don't fill the parent width because of indicated dimensions 300x300, but I don't know how to change it to parent size.
TableView has constraints on the boundaries of the device. I also tried set constraints for the cell but it didn't help.
You should set constraints in your image and on entire UITableViewCell xib just like in ViewController
This is a very basic design task. You really should take the time to go through a few tutorials on Auto-Layout.
The comment you posted: "Adding constraints in the UITableViewCell xib is not possible for me," along with the image, indicates you are selecting the Content View in your cell xib, but that is not where you want to add constraints.
You need to constrain the elements in your cell to the content view:
which results in a table view (at run-time) that looks like this:

UITableviewCell Dynamic Height Programmatically with the use of UITableViewAutomaticDimension

Hi Guys here i am suffering issue of dynamic height of UITableview Programmatically. I have set Autolayout of all view without any error
but lblDesc (UILabel) not expand with its size according to content. plz guide me
sometimes I do not need btnVideo (UIButton) so i have to hide btnVideo(UIButton) and dynamically all social networks UIButton come after lblDesc (UILabel)
Here i attached my code with only one view
UITableViewAutomaticDimension
https://drive.google.com/file/d/0B5mabdphYDhzWG9UMzM2MTV6cms/view?usp=sharing
You should use UITextView instead of UILabel.
Btw, never forget you setup constraints between text view and container views for all edges correctly, so according to your text size, the whole cell will be resized dynamically.
I have reviewed your code. tableview has correct setting.
Just setup correct layout constraints so that table view could know how it should change the height of cell.
Cheers

UITableView resize cell based on content

Hi I need help with understanding how to resize cell based on its content.
So first of all of course I found many links:
iOS: Multi-line UILabel in Auto Layout
https://www.youtube.com/watch?v=CkvZEJ7dIfw
https://github.com/williamhqs/GSTableViewDynamicHeight
As we said about git example (last link) I can't understand how to change some label and make it works. For example if I delete UILabel and create new one and bind it with content property (content - it is IBOutlet property of bottom label). I seems lost some setting and cell won't stretch.
So I think I don't know to much understanding how to do it.
What I want to understand:
How to setup auto layouts in the storyboard or programmatically.
Which thing I should handle programmatically to make it done.
How the preferred size affects on label. Do we need every time use bonds of superview as a preferred size?
Also in the git example we have one label that changes itself size. What if we have 2 UILabels with dynamic content how to setup it?
If you have some links or videos please drop them here, because I really stuck. Thank you!
I know it's duplicated question but I can't understand how to setup it.
To make Self Sizing Cells works there is three steps:
Setup correctly the constraints of the cell (most important the top and bottom constraints)
Specify the estimatedRowHeight of your table view
Set the rowHeight of your table view to UITableViewAutomaticDimension
for step 2 and 3 it's so easy just add these two lines in you viewDidLoad method
tableView.estimatedRowHeight = 44.0 // or whatever you want
tableView.rowHeight = UITableViewAutomaticDimension
for step 1 which is the most important part of self sizing process
what you need to keep in mind is that "self-sizing needs to get its size from your constraints."
Basically we need to make sure that top space and bottom space constraints of our cell is correctly set up here is an example :
just two labels with the constraints top,bottom,right and left space to each other and to container (see image) the UILabels Lines property is 0 so that you allow have multiple lines
Another example from a project that I am working on:
bottom line:
The label constraints should push against the size of the table view cell and make it taller. So always check the top and bottom constraints.
Also you may run intro trouble working with UILabel with multi-lines because
The intrinsic content size of UILabel and NSTextField is ambiguous for
multi-line text.
so make sure always to setup the preferredMaxLayoutWidth property of yout label:
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentLabel.preferredMaxLayoutWidth = self.contentLabel.frame.size.width;
}
for more infrmation about this issue here read :
iOS Autolayout multi line UILabel
iOS multi-line UILabel in Auto-layout
preferredMaxLayoutWidth
And for more information about Dynamic Table View Cell Height in general here is some useful resources:
UITableView Tutorial: Dynamic Table View Cell Height
Understanding Self Sizing Cells and Dynamic Type in iOS 8
Self Sizing Table View Cells
Mysteries of Auto Layout, Part 1 (wwdc 2015)
Not sure if it will apply to AutoLayout, although when laying out a cell programmatically, running "layoutIfNeeded()" fixed my cell content stretch issue.
layoutIfNeeded was ran at the end of a configure method, used to map values (view model) to UI objects (views)

Change height of UIView inside of UITableViewCell (Storyboards)

I'm trying to create a master UITableViewCell with storyboards. The idea is that this cell contains all the possible subviews, but not all will be shown depending on the data for each cell.
I calculate the appropriate height for each cell depending on the data using the heightForRowAtIndexPath and this is working fine.
What I'm trying to figure out is how to adjust the height of subviews to zero inside the tableViewCell to effectively hide those elements while still respecting the relative constraints I set up (unlike removing the subviews from the superview which messes up all my constraints).
So basically I can't seem to figure out how to update the height(frame) of a subview (UIView) inside a UITableViewCell using storyboards and autolayout.
Any guidance would be awesome, and please let me know if I'm not using the best paradigm or thought process for the desired effect.
Best,
emjoseph
You'll need to use NSLayoutConstraint's. If your cell subviews do not already have fixed heights, you'll need to add them.
Once you've added those constraints, create references to your header file for those constraints. To do this, double click the height constraint so that it reveals itself in your ViewController structure, then control click and drag into your header file.
When you've decided which view to collapse, access your newly declared NSLayoutConstraint and edit the constant value.
Example:
subviewHeight.constant = 0;

Self Sizing UITableViewCells with UITextViews

I am using sizing classes to make two separate layouts for a UITableViewCell. I am using IB to create all of the constraints. I have four UILabels and one UITextView in the cell. The wAny, hAny class works perfectly.
The hCompact, wRegular class was getting a broken vertical constraint, which I fixed by giving the vertical spacing constraint from the UITextView to the content view a 999 priority instead of 1000.
An issue still exists that causes the UITextView to collapse all the way (or the cell to be sized such that it covers the UITextView completely) when the cells are first presented. All out-of-view cells render fine when they come into view, and the original cells also render appropriately when they come back into view after going out of view.
I want to be able to use self-sizing cells and have the UITextView render correctly upon load. It would also be nice to know why I had to set the priority of the constraint to 999 to fix that layout warning at run-time.
This is only occurring on my hCompact, wRegular class which, in my opinion, has a less vertically complex set of constraints set up than the other sizing class. I have included an image of the UITextView selected and showing the constraints on the right. I gave the UITextView a lime background for debugging. As you can see, it looks rather odd in IB. I will provide any other info as requested.

Resources