I'm doing an assignment from a book for learning iOS development. The assignment requires that the name label at the upper left area of a table cell should be able to display multiple lines if the name is too long and it should not go beyond the leading constraint of the value label at the far right of the same cell like this:
Besides the other usual constraints, I added the trailing constraint to the name label, which is equal to the trailing constraint of the value label, like this:
And the run result is like the following:
The name label text undesirably runs over the top of the value label text.
I've also tried to add a horizontal space between the name label and the value label, but the compiler reported a conflict of constraints. Would you please tell me what I should do to make it right?
Thank you very much!
If you typed that correctly, then your problem is you set the trailing anchor of the name label equal to the trailing anchor of the value label. That would mean that the right edge of each label has to be equal. You don't want that. The system is probably breaking your constraint and making its own weird one instead which is causing the undesirable behavior.
Set the trailing anchor of the name label equal to the leading anchor of the value label minus some constant (whatever padding you want).
Programmatically you do something like this
nameButton.translatesAutoresizingMaskIntoConstraints = false
nameButton.trailingAnchor.constraint(equalTo: valueButton.leadingAnchor, constant: -10)
If you must use storyboard, which I advise against in general, I think this or some other tutorial page will show you how. I don't know how to use storyboard very well at all.
https://www.raywenderlich.com/811496-auto-layout-tutorial-in-ios-getting-started
tried this one, hoping the following is the result you required
in order to acquire this
once we select the horizontal spacing we have to change according to our need
in-order to change select title label then select size inspector from the
right window
then change the trailing space to the amount label
now given constraints for title label
once it given it will show error in the constraints since the amount label constraints are not given
next have to give constraints for amount label
now try to input larger text values in title label
look like one more step to complete
in order to get multiple line change the number of line property value of title label to 0 in attribute inspector
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.