Sections 7 : Color Literal and Image Literal
Use the color picker and images list to set your colors and images directly in the code
Xcode has the ability to embed colors and images directly in code. This is done with the help of Color Literals and Image Literals.
Color Literal
A color literal allows you to select colors using a color picker directly from your code. You can either select a color or type in the HEX code. You can also set the opacity.
Code:
let color0 = Color(#colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1));
let color1 = Color(#colorLiteral(red: 0.3647058904, green: 0.06666667014, blue: 0.9686274529, alpha: 1));..
Image Literal
Similar to color literals, image literals opens up a GUI from where you can select all the images in your Assets Catalog.
You can download free images from https://www.freepik.com/.
var body: some View {
let image0 = #imageLiteral(resourceName: "fish1")
VStack {
Image(uiImage: image0)
}
}..




Comments
Post a Comment