天天看點

SwiftUI - Text

文章目錄

    • BasicStyle
    • Paragraph
    • Padding
    • FullScreen
    • DateFormatter
    • Append

Learn from:http://www.coolketang.com/hdjc/swiftUI/

BasicStyle

SwiftUI - Text
struct ContentView : View {
    
    var body: some View {
        
            VStack{
                //Basic style
                Text("Hi, SwiftUI")
                    .bold()
                
                Text("Hi, SwiftUI")
                    .italic()
                
                Text("Hi, SwiftUI")
                    .underline()
                
                Text("Hi, SwiftUI")
                    .underline(true, color: .purple)
                
                Text("Hi, SwiftUI")
                    .strikethrough()
                
                Text("Hi, SwiftUI")
                    .strikethrough(true, color: Color.blue)
                
                Text("Hi, SwiftUI")
                    .foregroundColor(Color.pink)
                    .foregroundColor(Color.blue)
                
                Text("Hi, SwiftUI")
                    .baselineOffset(CGFloat(5.0))
                    .background(Color.red)

                 Text("Hi, SwiftUI")
                     .background(Image("Picture"), alignment: .bottom)
                
                //Font
                VStack{
                    Text("Hi, SwiftUI")
                        .font(.footnote)
                    
                    Text("Hi, SwiftUI")
                        .font(.system(size: 36))
                    
                    Text("Hi, SwiftUI")
                        .font(.system(.title, design: .monospaced))
                    
                    Text("Hi, SwiftUI")
                        .font(.custom("BradleyHandITCTT-Bold", size: 36))
                    
                    Text("Hi, SwiftUI")
                        .fontWeight(Font.Weight.heavy)
                    
                    Text("Hi, SwiftUI")
                        .fontWeight(Font.Weight.ultraLight)
                    
                }
            
        }
 
        
    }
}
           

Paragraph

SwiftUI - Text
struct ContentView: View
{
    var body: some View
    {
        VStack
        {
            Text("Interactive tutorials.")
            
            Text("Hi, SwiftUI")
                .tracking(10)

            Text("Hi, SwiftUI")
                .kerning(5)

            Text("Hi, SwiftUI blur")
                .blur(radius: 1)
            
            Text("SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift.")
                .lineSpacing(2)
                .lineLimit(nil)

            Text("Hi, SwiftUI")
                .offset(x: 40, y: 0)

            Text("Hi, SwiftUI")
                .frame(width: 200, height: 65, alignment: .center)
                .background(Color.yellow)
            
            VStack
            {
                Text("Hi, SwiftUI")
                    .position(x: 50, y: 50)
                    .frame(width: 300, height: 100, alignment: .bottomTrailing)
                    .background(Color.red)
                
                Text("Interactive\ntutorials\nfor\nXcode!")
                    .lineLimit(4)
                    .frame(width: 200, height: 100)
                    .multilineTextAlignment(.center)
            }
        }
    }
}
           

Padding

SwiftUI - Text
VStack{
            Text("Hi, SwiftUI")
                .background(Color.black)
                .foregroundColor(.white)
                .padding(20)
           
            Text("Hi, SwiftUI")
                .padding()
                .background(Color.black)
                .foregroundColor(.white)
            
            Text("Swift User Interface")
                .font(.largeTitle)
                .foregroundColor(.black)
                .padding(15)
                .background(Color.yellow)
                .padding(15)
                .background(Color.blue)
                .padding(10)
                .background(Color.red)
        }
           

FullScreen

SwiftUI - Text
struct ContentView : View {
    
    var body: some View {
        Text("Hi, SwiftUI")
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
            .background(Color.yellow)
            .font(.largeTitle)
            .edgesIgnoringSafeArea(.all)
    }
}

           

DateFormatter

SwiftUI - Text
struct ContentView : View {
    
    var now = Date()
    static let dateFormatter: DateFormatter =
    {
        let formatter = DateFormatter()
        formatter.dateStyle = .long
        
        return formatter
    }()
    
    var body: some View
    {
        Text("The time is: \n \(now, formatter: Self.dateFormatter)")
            .font(.title)
            .padding()
    }
}
           

Append

SwiftUI - Text
Text("Interactive ")
            .foregroundColor(.yellow)
            .fontWeight(.heavy)
            
        + Text("tutorials ")
            .foregroundColor(.orange)
            .strikethrough()
            
        + Text("for ")
            .foregroundColor(.red)
            .italic()
            
        + Text("SwiftUI")
            .foregroundColor(.purple)
            .underline()
        
           
上一篇: mongodb 應用
下一篇: apple touch icon

繼續閱讀