I need to implement a news feed like instagram but I'm facing some troubles with my constraints.
I have a tableView cell with: imageView, label 1, label 2, view 1 and view 2 in a vertical order like this:
I need to achieve the following conditions:
- my image is square.
- label 1 (the black one) have 5 lines max
- label 2 (the red one) don't have a max number of lines
- view 1 is 30px height
- view 2 is 35px height
My constraints are:
Image:
- trailing space to superview
- leading space to superview
- top space to superview
- botton space to label 1 with constant=8
- height = 320 with priority=999 (during runtime I change this value to view's width)
- Content hugging - Vertical = 751, Horizontal=751
- Content compression - Vertical = 1000, Horizontal = 751
Label 1:
- trailing space to superview with constant=-20 and priority=999
- leading space to superview with constant=20
- height >=20 with priority= 750
- bottom space to label2 with constant=8
- Content hugging - Vertical = 1000, Horizontal=752
- Content compression - Vertical = 1000, Horizontal = 751
Label 2:
- trailing space to superview with constant=-20 and priority=999
- leading space to superview with constant=20
- height >=20 with priority= 750
- bottom space to view1 with constant=8
- Content hugging - Vertical = 1000, Horizontal=752
- Content compression - Vertical = 1000, Horizontal = 751
View 1:
- trailing space to superview
- leading space to superview
- botton space to view2
- height = 30
- Content hugging - Vertical = 1000, Horizontal=250
- Content compression - Vertical = 1000, Horizontal = 750
View 2:
- trailing space to superview
- leading space to superview
- botton space to superview
- height = 35
- Content hugging - Vertical = 1000, Horizontal=750
- Content compression - Vertical = 1000, Horizontal = 750
During runtime I receive several warning about constraints. It can't satisfy all my constraints.
"<NSLayoutConstraint:0x7fec35712d60 V:[UIView:0x7fec357391e0(30)]>",
"<NSLayoutConstraint:0x7fec3570a8f0 V:[UIView:0x7fec357432a0(35)]>",
"<NSLayoutConstraint:0x7fec350d17b0 V:|-(0)-[UIImageView:0x7fec35711340] (Names: '|':UITableViewCellContentView:0x7fec35744f30 )>",
"<NSLayoutConstraint:0x7fec350bf830 V:[UIImageView:0x7fec35711340]-(8)-[TimelineLabel:0x7fec3570a980'Usura']>",
"<NSLayoutConstraint:0x7fec350bc7e0 V:[TimelineLabel:0x7fec3570a980'Usura']-(8)-[UILabel:0x7fec350ddb40'Produtos: BATOM: MAC, SOM...']>",
"<NSLayoutConstraint:0x7fec35701f20 V:[UILabel:0x7fec350ddb40'Produtos: BATOM: MAC, SOM...']-(8)-[UIView:0x7fec357391e0]>",
"<NSLayoutConstraint:0x7fec350e90c0 V:[UIView:0x7fec357391e0]-(0)-[UIView:0x7fec357432a0]>",
"<NSLayoutConstraint:0x7fec350e9110 UIView:0x7fec357432a0.bottom == UITableViewCellContentView:0x7fec35744f30.bottom>",
"<NSLayoutConstraint:0x7fec357085c0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fec35744f30(0)]>"
Will attempt to recover by breaking constraint
NSLayoutConstraint:0x7fec3570a8f0 V:[UIView:0x7fec357432a0(35)];
For each cell in my tableView break a different constant.
I tried a lot of solutions but none works.
Help! Please!