美文网首页
SwiftUI组件基本用法

SwiftUI组件基本用法

作者: 张文进 | 来源:发表于2023-11-15 15:01 被阅读0次

Text的基本用法

struct TextView: View {
    var body: some View {
        Text("Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World")
            // 设置文字大小
            .font(.title)
            // 设置文字粗细
            .fontWeight(.heavy)
            // 设置文字下划线
            .underline(true,pattern: .dot,color: .red)
            // 设置文字斜体
            .italic(true)
            // 设置文字中横线
            .strikethrough(true,color: .green)
            // 设置文字大小,样式,粗细
            .font(.system(.title2,design: .monospaced,weight: .medium))
            // 多行文字居左显示
            .multilineTextAlignment(.leading)
            // 单个字符的间距
            .kerning(5)
            // 文字的颜色
            .foregroundColor(.pink)
            // 布局范围
            .frame(width: 200,height: 200,alignment: .leading)
            // 文字在布局范围内自适应
            .minimumScaleFactor(0.1)
    }
}

形状的基本用法

struct ShapeView: View {
    var body: some View {
        // 圆形
//        Circle()
        // 椭圆形
//        Ellipse()
        // 按钮形状
//        Capsule(style: .continuous)
        // 矩形
//        Rectangle()
        // 矩形 设置圆角 20
        RoundedRectangle(cornerRadius: 20)
            // 设置颜色
//            .fill(.red)
//            .foregroundColor(.pink)
            // 边框宽为5
//            .stroke(.blue,lineWidth: 5)
            // 边框样式 由20个虚线组成的圆
//            .stroke(.green, style: StrokeStyle(lineWidth: 10,lineCap: .butt,lineJoin: .bevel,dash: [20]))
            // 半圆 大半圆
//            .trim(from: 0.2,to: 0.8)
//            .stroke(.blue,lineWidth: 5)
            .frame(width: 200,height: 100)

            
    }
}

渐变色

 RoundedRectangle(cornerRadius: 20)
            .fill(
                // 线性渐变
//                LinearGradient(colors: [.red,.blue], startPoint: .leading, endPoint: .trailing)
                // 发散性渐变
//                RadialGradient(gradient: Gradient(colors: [.red,.blue]), center: .center, startRadius: 100, endRadius: 300)
                // 角度性渐变
                AngularGradient(colors: [.red,.blue], center: .leading, startAngle: .degrees(0), endAngle: .degrees(300))
            )
            .frame(width: 300,height: 200)

图片设置

Image("qidongtu")
//            .renderingMode(.template)
        // 图片原尺寸
            .resizable()
        // 图片宽高比 和 展示形式
//            .aspectRatio(1.5, contentMode: .fill)
        // 适应图片尺寸
            .scaledToFit()
        // 范围撑满
//            .scaledToFill()
            .frame(width: 100,height: 100)
        // 当设置图片 renderingMode(.template) 时 可以修改图片的颜色
//            .foregroundColor(.red)
        // 图片裁剪
            .clipped()

相关文章

  • swiftUI 常用控件介绍

    最近在学习swiftUI,首先来介绍一下swiftUI的一些基本用法,swiftUI和Flutter的语法比较类似...

  • 为小组件构建 SwiftUI 视图

    为小组件构建 SwiftUI 视图为小组件构建 SwiftUI 视图

  • 高阶组件

    Hoc(高阶组件) 概念 hoc基本用法 hoc链式调用 hoc装饰器用法 概念 概念: 接受组件, 返回新组件,...

  • Router路由

    基本用法: 详细用法 在脚手架组件中使用路由: main.js:

  • SwiftUI 合集组件之常用UIKit封装为SwiftUI组件

    实战需求 SwiftUI 合集组件之常用UIKit封装为SwiftUI组件 (教程含源码) 本文价值与收获 看完本...

  • ReactNative网络fetch数据并展示在listview

    看完全文并且do it你将收获: fetch获取网络数据的基本用法ListView的基本用法RN中组件的生命周期(...

  • vue中ref的作用

    基本用法 1 本页面获取dom元素 2 获取子组件中的data子组件 父组件 3 调用子组件中的方法子组件 父组件...

  • 【Vue】组件 - 插槽默认值

    基础知识 【Vue】组件 - 插槽的基本用法 【Vue】组件 - 多个插槽 子组件里,在 里写上默认的内容。 在父...

  • 插槽的使用

    1. 插槽和组件的区别 插槽和组件的用法基本相同,主要的区别是父组件可以在插槽中自定义子组件的DOM 2.基本使用...

  • SimpleLog文档

    simpleLog 基于封装,基本的用法如下: 1. 用法: 在页面写入组件,给其指定相应的...

网友评论

      本文标题:SwiftUI组件基本用法

      本文链接:https://www.haomeiwen.com/subject/vabswdtx.html