Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Fakher
Courses Plus Student 1,675 Pointsthe story does't displayed when i press the 'Start your Adventure' button??
override func viewDidLoad() {
super.viewDidLoad()
if let page = page{
artworkView.image = page.story.artWork
let attributedString = NSMutableAttributedString(string: page.story.text)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
storyLabel.text = page.story.text
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
view.addSubview(artworkView)
artworkView.translatesAutoresizingMaskIntoConstraints = false // to cannot makes conflict in constraints when the new sub view added
// image constraint
NSLayoutConstraint.activate([
artworkView.topAnchor.constraint(equalTo: view.topAnchor),
artworkView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
artworkView.rightAnchor.constraint(equalTo: view.rightAnchor),
artworkView.leftAnchor.constraint(equalTo: view.leftAnchor)
])
// label constraints
view.addSubview(storyLabel)
storyLabel.numberOfLines = 0
storyLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
storyLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16.0),
storyLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16.0),
storyLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: -48.0)
])
}
Marlon Henry
6,885 PointsMarlon Henry
6,885 PointsCan I see the code that you have in the IBaction for when you press the button?
Also
storyLabel.text = page.story.text
sets the value for that label once the view loads, so basically this is the default text for the button as soon as it loads(assuming you're fine with this)