Lesson 3 Flashcards
SwiftUI Grab Bag
Text in SwiftUI
Text (text element) –> built in text styles, environment based modifiers (changes specific text)
built in styles support many modifiers
(.font, .fontWeight, .lineLimit, etc)
why use built in text styles?
- Dynamic type
- Bold text
- semantic names –> consistency across app
Color in SwiftUI
similar to Text –> built in colors
why use built in colors?
- light and dark mode –> adapt to light and dark mode easily
- increase contrast
how are colors easily used by SwiftUI?
color conforms to view (can be used anywhere)
access defaults as static properties (Color.primary, Color.secondary)
default colors good for text
.primary –> default
.secondary
^ adapt to light and dark mode by default
primary text light mode –> black
primary text dark mode –> white
secondary is gray in both
what are the bounds of the safe area?
views stay within safe area by default –> from below battery, etc bar to above home swipe bar (between dynamic island and home indicator)
why is there a safe area?
makes sure content isn’t obscured
how would you ignore this safe area to cover the whole screen?
.ignoresSafeArea() (on desired view)
.background(_:ignoresSafeArea:)
two main kinds of swift images
- SF Symbols –> builtin symbol library
- Custom images –> imported into Assets catalog
how to declare SF Symbol
Image(systemName: “symbol name”)
what are SF Symbols used for?
icons
how to use custom image
Image(.nameOfImage)
what size are custom images by default?
their true size, declared width and height in pixels –> probably very large or very small depending on quality
how would you resize image?
.resizable() // this
.scaledToFit() // or this
.frame(width: #, height: #) //optional
clip shape
allows you to customize the shape of your views (images)
Image(.oldWell)
.resizable()
.clipShape(.rect(cornerRadius: 16))
what does this do?
clips the image of the old well to be in a rectangular shape with rounded corners by size 16