Date : March 29 2020, 07:55 AM
seems to work fine iOS 6+ Using Auto Layout Table View with Header and Footer because cells in between are static (static cells are only supported in a UITableViewController, not a UITableView in a normal UIViewController..) , Fixed by checking "Clip Subviews" in IB.
|
Auto-Layout: Get UIImageView height to calculate cell height correctly
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , So I think the underlying issue is a kind of chicken and egg problem. In order to 'aspect fit' the image to the UIImageView the system needs a size for the view, and yet we would like the height of the view to be determined after aspect fitting the image given a known width for the view. class CustomCell: UITableViewCell {
@IBOutlet weak var imageTitle: UILabel!
@IBOutlet weak var postedImageView: UIImageView!
internal var aspectConstraint : NSLayoutConstraint? {
didSet {
if oldValue != nil {
postedImageView.removeConstraint(oldValue!)
}
if aspectConstraint != nil {
postedImageView.addConstraint(aspectConstraint!)
}
}
}
override func prepareForReuse() {
super.prepareForReuse()
aspectConstraint = nil
}
func setPostedImage(image : UIImage) {
let aspect = image.size.width / image.size.height
aspectConstraint = NSLayoutConstraint(item: postedImageView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: postedImageView, attribute: NSLayoutAttribute.Height, multiplier: aspect, constant: 0.0)
postedImageView.image = image
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomCell
cell.imageTitle.text = titles[indexPath.row]
let image = images[titles[indexPath.row]]!
cell.setPostedImage(image)
return cell
}
|
Use AutoLayout to scale down UIImageView height
Date : March 29 2020, 07:55 AM
This might help you UITextField constraints: Leading space, Trailing space, Top space to UIView margins constraints + Height constraint of the textfield.
|
UIImageView height not height of child image's height after autolayout constraints.
Date : March 29 2020, 07:55 AM
like below fixes the issue Add the following constraint to the imageView: "aspect ratio" constraint with the multiplier set to the imageView's aspect ratio.
|
Constraining UIImageView height to respect dynamic UILabel height in UITableViewCell
Tag : ios , By : user87752
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Try setting thumbnail vertical compression resistance lower than title vertical hugging priority. In code it'll look like this: thumbnail.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
titleLabel.setContentHuggingPriority(.required, for: .vertical)
|