当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Swift Optional border(_:width:)用法及代码示例


实例方法

border(_:width:)

使用指定的样式和宽度向此视图添加边框。

声明

func border<S>(
    _ content: S,
    width: CGFloat = 1
) -> some View where S : ShapeStyle

返回值

向此视图添加具有指定样式和宽度的边框的视图。

参数

content

符合 ShapeStyle 协议的值,如 ColorHierarchicalShapeStyle ,SwiftUI 用于填充边框。

width

边框的粗细。默认值为 1 像素。

详述

使用此修饰符在视图框架周围绘制指定宽度的边框。默认情况下,边框出现在此视图的边界内。例如,您可以添加一个four-point 宽边框覆盖文本:


Text("Purple border inside the view bounds.")
    .border(Color.purple, width: 4)

要在此视图的外部放置边框,请在添加边框之前应用相同宽度的填充:


Text("Purple border outside the view bounds.")
    .padding(4)
    .border(Color.purple, width: 4)

可用版本

iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+

相关用法


注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Optional border(_:width:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。