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 2 Creating the User Interface Programmatically Attributed Strings

Kevin Gutowski
Kevin Gutowski
4,082 Points

Seems like setting paragraph styles is quite a burden compared to design tools like Sketch.

While I understand that we are applying stylistic properties to a basic component (a string), I would have thought that Xcode would have provided some default functions to be able to manipulate paragraph styles much easier. For example, you commonly want to set a line height that is dependent on the font size (rather than specifying the exact size). I suppose that when displaying text people would want to customize how it is displayed so often that Xcode would be able to help us out a bit more.

1 Answer

Jari Koopman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Points

Hi Kevin,

I might be wrong but I think that all this is achievable if you use storyboards (I'm not sure though). But I also think that this can be done in code, just try googling it or have a look on stack overflow.

Hope this helped,

Regards, Jari

Kevin Gutowski
Kevin Gutowski
4,082 Points

Sure, but even the best suggestions I find online is using attributedString attributes which just seems insane to me. Like why would the default function require you to specify a range in the first place? Just seems like the way attributedStrings are setup is awful and I would probably just write some sort of extension or wrapper for doing basic functionality such as setting a paragraphs font size...

Ben Shockley
Ben Shockley
6,094 Points

I would imagine if you're doing a whole lot of attributed string adjustments by code, you could pretty easily build a framework, or extension as you said, that would streamline the process. As a company, I am sure Apple wants to make things as easy as possible for the most amount of people, but there's also a line to walk between making it easy, and keeping it flexible and powerful at the same time.

That being said, these are Obj-C functions and systems that you're working with, so they're probably pretty old and established in the way that they work. I also wouldn't be surprised if they had plans to streamline this process in swift as it becomes more developed over time.

Just my thoughts on it.

-- Ben