UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 8, Day 36 - labels not stretching w/ setContentHuggingPriority

Forums > 100 Days of Swift

A low priority is suppose to make the label stretch easily. Changing default priority to 1 using setContentHuggingPriority(UILayoutPriority(1), for: .vertical) not working here:

    cluesLabel = UILabel()
    cluesLabel.translatesAutoresizingMaskIntoConstraints = false
    cluesLabel.font = UIFont.systemFont(ofSize: 24)                                 //gives us the current Apple font
    cluesLabel.text = "CLUES" //placeholder
    cluesLabel.numberOfLines = 0                                                    //how many lines will this text wrap over ~  0 => as many as it takes
    cluesLabel.setContentHuggingPriority(UILayoutPriority(1), for: .vertical)       //Stretch [& Squash] priority setting... Low priority = make it stretch easily
    view.addSubview(cluesLabel)

    answersLabel = UILabel()
    answersLabel.translatesAutoresizingMaskIntoConstraints = false
    answersLabel.font = UIFont.systemFont(ofSize: 24)
    answersLabel.text = "ANSWERS"                                           //placeholder
    answersLabel.textAlignment = .center                                             
    answersLabel.numberOfLines = 0                                         //how many lines will this text wrap over ~  0 => as many as it takes
    answersLabel.setContentHuggingPriority(UILayoutPriority(1), for: .vertical)       //Stretch [& Squash] priority setting... Low priority = make it stretch easily
    view.addSubview(answersLabel)

Very stumped. After seeing identical solutions on github, I am scratching my head as to why my labels don't look like the desired UI... https://youtu.be/yhxhKpyyQzE?t=1808

Maybe a Swift 5.2 issue? Thanks!

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.