SwiftUI - Text Example With Properties.

This tutorial is to display Text in SwiftUI. We are use the UILabel to display text in Swift.  Now here in SwiftUI there is introduce a new class called Text which is used to display text.Here we are study how to define Text and what's its properties. first you create SwiftUI Project.



Create SwiftUI Project : 

We are apply below properties on SwiftUI Text :

1. kerning : Space between the characters.
2. italic/bold : Style of the bold/italic.
3. frame : position and dimension of the SwiftUI Text.
4. font : Predefine font size or custom font size on SwiftUI Text.
5. foregroundColor : SwiftUI Text Colour.
6. lineLimit : Number of line SwiftUI Text.
7. multiLineTextAlignMent : alignment of SwiftUI Text.
8. lineSpacing : Space between two line SwiftUI Text.
9. background : Colour of background SwiftUI Text.
10. truncationMode :  Mode is tail/middle etc, 
11. transformEffect : Effect on SwiftUI Text.
12. Shadow : give radius and Colour of shadow.

Full Code of Text SwiftUI:
//  Created by Kirit Modi on 17/09/19.
//  Copyright © 2019 iOSDevCenters. All rights reserved.
//

import SwiftUI

struct ContentView: View {

    var body: some View {

        Text("iOSDevCenters \n www.iosDevcenters.blogpost.com")
            .kerning(2)
            .italic()
            .frame(minWidth: 0, maxWidth: 300, minHeight: 0, maxHeight: 200)
            .font(.headline)
            .foregroundColor(Color.red)
            .lineLimit(2)
            .multilineTextAlignment(TextAlignment.center)
            .lineSpacing(2)
            .background(Color.yellow)
            .truncationMode(Text.TruncationMode.tail)
            .transformEffect(CGAffineTransform.init(rotationAngle: 0))
            .shadow(radius: 3)
            .shadow(color: Color.black, radius: 3, x: 1, y: 1)

    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
SwiftUI Text Output : 



Create SwiftUI Project before the run code.

Thanks.

Checkout the Jooble if your are looking for a job as an iOS developer. 
SwiftUI - Text Example With Properties. SwiftUI - Text Example With Properties. Reviewed by KIRIT MODI on 00:00:00 Rating: 5

No comments:

Powered by Blogger.