★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(let_us_code)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址: https://www.cnblogs.com/strengthen/p/12259935.html
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

热烈欢迎,请直接点击!!!

进入博主App Store主页,下载使用各个作品!!!

注:博主将坚持每月上线一个新app!!!

本文演示文本视图的内部填充属性,

可以使用填充属性,修改文字内容和文本视图边框之间的距离。

即修改文本视图上下左右的内边距。

 1 import SwiftUI
 2 
 3 struct ContentView : View {
 4     var body: some View {
 5         VStack{
 6             //新建文本视图
 7             Text("www.zengqiang.org")
 8                 //黑色背景颜色
 9                 .background(Color.black)
10                 //白色前景颜色,即文字颜色
11                 .foregroundColor(.white)
12                 //设置填充属性的值为20,
13                 //增加文本视图与文字内容的间距。
14                 .padding(20)
15             
16             //新建文本视图
17             //链式调用的顺序由上而下进行
18             Text("www.zengqiang.org")
19                 //设置文本视图的内边距
20                 .padding()
21                 //背景颜色,此时内边距也会拥有相应的背景颜色
22                 .background(Color.black)
23                 //字体颜色
24                 .foregroundColor(.white)
25             
26             //新建文本视图
27             Text("Swift User Interface")
28                 //设置文字内容的样式为巨型标题样式,以突出显示文字内容。
29                 .font(.largeTitle)
30                 .foregroundColor(.black)
31                 //填充属性为15,增加文本视图与文字内容的间距
32                 .padding(15)
33                 //设置背景颜色为黄色
34                 .background(Color.yellow)
35                 //填充属性为15,在文本视图的外围再次增加15点的间距
36                 .padding(15)
37                 //给新的内边距设置填充颜色为橙色
38                 .background(Color.orange)
39                 //设置填充属性的值为10,在文本视图的外围再次增加10点的间距
40                 .padding(10)
41                 //给新的内边距设置填充颜色为红色
42                 .background(Color.red)
43                 //从而给文本视图添加由红至黄的渐变边框
44         }
45     }
46 }
47 
48 
49 #if DEBUG
50 struct ContentView_Previews : PreviewProvider {
51     static var previews: some View {
52         ContentView()
53     }
54 }
55 #endif

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案