I'm trying to create a simple reusable table section header view pictured as such:
I'd like the height of the label to be resizable and a padding of 10 from the top and bottom.
I keep getting the conflicting constraints error. I don't see why it can't simultaneously satisfy these constraints.
Also, while experimenting, if I set the height to <= 45, it all works. I'm confused why.
Could someone point me in the right direction?
UIview height should be bigger than 65
Oddly enough when I set up similar constraints, I was getting a similar error, but when I stretched the view out from the bottom right far enough, the constraint errors went away. Either way, when I run the app, I wasn't getting an error read out.
Related
I have a custom UITableViewCell, it looks like this:
The warning I'm getting is:
Inequality Constraint Ambiguity: trailing >= date.trailing + 16
I highlighted the constraint in the picture above.
What I don't understand is, before 'someView' (the last view in the bottom) was added, there was no warning; When it was added without height = 20 constraint, there was no warning. However, as soon as the height constraint was added, I start to get the warning message.
I have to add the height constraint because without the it, the height of 'someView' is not 20 anymore.
If it helps, I am using
tableView.rowHeight = UITableView.automaticDimension
to decide the height of a row
I used the same UI of yours in UITableViewCell:
The fields with width , height and aspect ratio has constraints as :
and all the remaining `constraints are as follows:
The only difference is I guess the height constraint to Name Label. If I am adding that then I am getting constraint conflict issues. Removing that is not showing any issues and UI is also perfectly fine.
Hope this helps to figure out and fix your issue.
You’ve added a lot of unneeded heights for a dynamic cell. I honestly hate seeing labels with height constraints, as contentSize will set that height for you. When I used to run into layout issues, my Senior IOS Developer would tell me to delete it all and start again, lol. I would suggest this but it would be a terrible answer. It’s also bad practice to have placeholder text in your labels/views. For some reason interface builder hates it. Just some tips.
You can download the example here: http://s000.tinyupload.com/index.php?file_id=02066350701605990856
I'm having an issue using Xcode 8.1 that I haven't had before. I have a UITableView inside a ViewController and have pinned it using constraints to top (0), left (0), right (0) and bottom (0).
When I've done this before the table view expands and contracts so is always centred on all screen sizes.........but please see the screenshot for my current results.
I've tried removing all constraints associated with that view and trying "Reset to Suggested Constraints" but that didnt change anything and have also attempted to build all the constraints back in manually, but still no luck.
Any suggestions or am I missing something really obvious!
Thanks
"Reset to Suggested Constraints" nearly always gives you something you don't want. It looks like your view at the top needs the constraints fixed first, then the tableview.
The first black view should be pinned to the top, right and left sides with no width, and a height specified. The tableview should be 0 all the way around.
If that doesn't work, can you share the starboard file?
I have a view that is sandwiched between two other views, and the height of the middle view can be changed through pan gesture.
I'm using a gesture recognizer to get the location of touch and feeding the value to the middle view's height constraint to make it dynamically resizable.
One issue is when the touch location goes beyond the middle view's bounds and overlaps with either the top view or the bottom view, I get the warning:
Unable to simultaneously satisfy constraints ...
Will attempt to recover by breaking constraint
This hasn't really caused any real issues but just in case it might cause a big problem, I'd like to know if
a) it's correct to use the height constraint to dynamically change the height
b) there is any way to avoid getting that warning logged
Thanks!
To answer your question:
a) Yes, this is the correct way to update the height of the view
b) Yes, there is a way to get rid of the warnings
Since your view gets negative values for the height constraints, you could add a check for the height so that you never set a negative value to it. Then, you won't have the error log anymore.
Not sure if you are supporting iOS 7 also, but if you are, the app will most probably crash because of the layout errors.
So, my suggestion would be to add something like this, to where you are updating the constraints:
[self.heightConstraint setConstant:MAX(0, value)];
Good luck with your project!
I have a pretty complex view and am trying to update it to work with autolayout (while I learn autolayout at the same time). Here is a screenshot of my view:
The only thing that you can't see is that all of these views are wrapped in a containerView and that container is sitting in a vertical scrolling UIScrollView.So if there was a really long description or something you would be able to scroll vertically.
My first problem is that I can't figure out how to get the descriptionView (red background) to adjust it's height dynamically (I have scrolling disabled in IB and again in code). I think it might be related to the bottom constraint to the imageScrollView.
The second problem is that the imageScrollView needs to be removed half the time. It holds multiple pictures of an item. But sometimes the item doesn't have pictures so I just want to remove the scrollView in that instance. I call removeSubview in code and want things to just readjust without having to set up a bunch of new constraints. So I added a top space constraint from the Question/Comments label to the bottom of the description and changed its priority to 900 instead of 1000. This seemed to solve my first problem and when I remove the imageScrollView the description view resized to the size of the content. However my scrollView that holds all of the content didn't scroll anymore, I am assuming that the containerView's height got screwed up or something.
Edit: the more I think about this the more I think that figuring out how to add a contraint for the size the descriptionView's height to match the content will solve the other problem as well. Here is another screenshot with the current constraints.
SOLUTION
I don't feel it is fair to post my own solution as the accepted answer. So I am posting my solution within the question, and giving the accepted answer to Nikita for trolling all the questions related to textViews being sized to their content.
My first problem is solved by using this: Github - Resizable Text View
The second issue was just a matter of setting up the constraints correctly. The red textView had a constraint to the bottom of the superview(contentContainer) (the superview which sets the height of the the main scrollView.) So when I removed textView then the contentContainer view didn't have a height constraint. So I ended up removing the constraint from the textView to the superview (which is the contentContainer) and made a constraint from the bottom of the commentTextView to the contentContainer. This solved the problem. Whenever I remove the red textView everything shrinks up the way I desire.
I'm not sure, that my solution is the best one, but I've done it in the following manner (I think that will help you with red text view): How do I size a UITextView to its content?
Unfortunately, I didn't understand you about second problem. Please, provide more details. Thanks!
Don't remove the image view. Just give it a zero-height constraint. That way you don't have to mess with any of your other constraints.
I'm having a heck of a time with using some of these constraints. I'm simply trying to add a UIView in the IB so that I can inject other views into as needed. However, I can not get the positioning right. No matter how many Constraints I add or remove I cannot seem to remove the 'Top Space to: Superview'. I'm simply trying to pin the UIView to the bottom and have it float up for the different screen sizes. This 'Top Space' is forcing the UIView off the screen and I can't seem to remove it nor de-prioritize it.
UIView Constraints (doesn't work) - sorry can't post images yet
http://i1322.photobucket.com/albums/u574/dneely79/uiview-constraints_zpscae66ed9.png
On another note though I can remove the UIView and add a UIImageView and I can get this to work. So, for now I'm actually injecting my views into this element instead of a UIView. Its working, just feels dirty.
UIImageView Constraints (Works)
http://i1322.photobucket.com/albums/u574/dneely79/uiimageview-constraints_zps726da545.png
Anyone else have any thoughts on how to overcome this? Its been driving me mad and doesn't seem to make much sense to me.
I've already tried this help link (though trying to anchor bottom and not top)
Xcode 4 and Interface Builder: Editing Vertical Spacing Constraint (Anchor Top, not Bottom)
Thanks ahead of time for any help or advice on this matter.
This was a semi-goofy mistake on my part based on the defaults that IB gives you. I went back and better analyzed my own pictures.
After noticing a height set on the UIImageView and not UIView, I added a height and was able to successfully delete the Top Space.