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 trial

iOS Build an Interactive Story App with Swift Creating the User Interface Programmatically Attributed Strings

Qasa Lee
Qasa Lee
18,916 Points

for Xcode 9 and Swift 4 there's a change we may encounter:

'NSParagraphStyleAttributeName' has been renamed to 'NSAttributedStringKey.paragraphStyle'

Hope this might help you.

Thanks a lot :)

3 Answers

Now it's 'NSAttributedString.Key.paragraphStyle'. (Add a "." before "Key").

Trevor Duersch
Trevor Duersch
9,964 Points

Is it just me, or is part of the text cut off? After I made that change (thanks, by the way!), the text only goes to "from the surface of Mars. It's" and stops there. This is what code I have

            let attributedString = NSMutableAttributedString(string: page.story.text)

            let paragraphStyle = NSMutableParagraphStyle()
            paragraphStyle.lineSpacing = 10

            attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))

            storyLabel.attributedText = attributedString

Anybody else seeing this? Or will it get resolved in the future videos?

you need to set storyLabel.numberOfLines = 0 after adding it as a subview

Joey Liu
Joey Liu
3,982 Points

Is it just me, after I added the code . Parsan requested as below:

if let page = page { artworkView.image = page.story.artWork

        let attributeString = NSMutableAttributedString(string: page.story.text)
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 10

        attributeString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributeString.length))



        storyLabel.attributedText = attributeString
    }

There is a Green Thread break point 1.1 at paragraphStyle = NSMutableParagraphStyle()