UICollectionView cell subviews do not resize
The solution was to turn off AutoConstraints for the cell xib and activate the flexible width/height arrows in the AutoResize for the imageviews.
Collection View Dynamic size (DID THE FOLLOWING BUT DIDNOT WORK)
I have also faced same issue so I did another approach. You need to add width constraint and you need to set it constant in systemLayoutSizeFitting function.
The main thing you should be careful about that is add all subviews to contentView of cell and also the last subview must has a constraint to bottom of contentView like the autoResizing TableViewCell
class ABCCell: UICollectionViewCell {
lazy var width: NSLayoutConstraint = {
let width = contentView.widthAnchor.constraint(equalToConstant: bounds.size.width)
width.isActive = true
return width
}()
override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
width.constant = bounds.size.width
return contentView.systemLayoutSizeFitting(CGSize(width: targetSize.width, height: 1))
}
}
Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only
contentView is broken. It can be also fixed in awakeFromNib
ObjC:
- (void)awakeFromNib {
[super awakeFromNib];
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
Swift3:
override func awakeFromNib() {
super.awakeFromNib()
self.contentView.frame = self.bounds
self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
Automatic Label Resize in UICollectionViewCell Not Working
Ok... So thank you to those who have helped. I have found out that my issue was indeed related to Auto-Layout constraints. I simply missed the box that said "Constrain to Margin".
UICollectionViewCell content wrong size on first load
It looks like it still retains it's 100x100px basic size for the contentView while the cell itself gets the right size already. You can force the layout to reset adding the following line just before you return the cell:
cell?.layoutIfNeeded()
Subviews do not resize properly when animating constraints
You need to call layoutIfNeeded()
in the animations block, not layoutSubviews()
.
(You should actually never call layoutSubviews()
yourself. It's a method called by the system during a layout pass and only intended for that purpose.)
Related Topics
How to Show/Hide a Uibarbuttonitem
iOS 7 Status Bar Collides with Navigationbar
How to Access My Viewcontroller from My Appdelegate? iOS
Sprite Moves Two Places After Being Paused and Then Unpaused
Uibutton Fails to Properly Register Touch in Bottom Region of iPhone Screen
It's Possible to Change Push Notification Message Before Display on Device from iOS Side
Application Loader Stuck at "Authenticating with the Itunes Store" When Uploading an iOS App
What's the Difference Between "Architectures" and "Valid Architectures" in Xcode Build Settings
Uialertview/Uialertcontroller iOS 7 and iOS 8 Compatibility
Including Custom Data into iOS Crash Dumps
My App Was Just Rejected for Using the Ad Support Framework. Which Library Is Responsible
Storing Images Locally on an iOS Device
Didreceiveremotenotification Not Working in the Background
How to Detect Swipe Gesture in iOS
Generate Random Numbers with a Given Distribution