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 trialJenny Swift
21,999 PointsIs there an equivalent of HTML and CSS in iOS development?
I've been working my way through the iOS courses here, and coming from web development, I'm noticing the absence of something like HTML and CSS. This surprises me, since I imagine that creating things without a markup language and stylesheets, or some sort of equivalent, would be very cumbersome. For example, how would I change the style of many things at once in iOS development? And is all the content created either programmatically or with Interface Builder, instead of something like HTML?
2 Answers
Michael Hulet
47,913 PointsThere isn't really an HTML/CSS equivalent on iOS. Interface Builder's raw format is based on XML, which HTML is also based on, but you don't work with Interface Builder's XML directly. You'll always make your interfaces with either Interface Builder or your own code
It's still important to not repeat yourself in iOS, however, just like in any form of code. Once you get used to keeping your interface code DRY on iOS, you'll likely end up finding it easier than with normal HTML/CSS/JavaScript. IBOutlet collections like how Awi mentions is definitely an important tool, but there are others as well. For example, if you have a common kind of view in your app, it's normal to make a UIView
subclass, apply your styling in that subclass, and use said subclass wherever you need to. Any changes to the subclass in your code will affect all instances of it. There's also the UIAppearance
protocol to make wide-ranging appearance changes throughout your app
Once you get used to building iOS interfaces and all the tools available to you in doing so, it'll be second-nature to you
Ali Nawab
13,869 PointsThe closest you will get to html/css is to use the Interface Builder and then to programmatically change the style of your elements, for example to change the style of all your buttons in a ViewController you can create an outlet for all the buttons:
@IBOutlet var allButtons: [UIButton]!
and then use a for loop to iterate over the buttons and give them a specific style:
for button in self.allButtons {
// style goes here
}
It is not as intuitive as using html/css especially for someone coming from web development but you can get used to it.
Jenny Swift
21,999 PointsThanks
Jenny Swift
21,999 PointsJenny Swift
21,999 PointsThat's encouraging. Thanks. :)