SwiftUI ZStack、HStack、VStack 布局

news/2024/10/5 15:29:50

代码

//
//  ContentView.swift
//  SwiftUIStacks
//
//  Created by CHEN Hao on 2024/5/6.
//import SwiftUIstruct ContentView: View {var body: some View {VStack(spacing:15) {HeaderView()HStack(spacing: 15) {PricingView(title: "Basic", price: "$9", textColor: .white, bgColor: .purple)ZStack {PricingView(title: "Pro", price: "$19", textColor: .black, bgColor: Color(red: 240/255, green: 240/255, blue: 240/255))Text("Best for designer").font(.system(.caption, design: .rounded)).fontWeight(.bold).foregroundStyle(.white).padding(5).background(Color(red: 255/255, green: 183/255, blue: 37/255)).offset(x:0, y: 87)}}.padding(.horizontal) // 水平外间距ZStack {PricingView(title: "Team", price: "$299", textColor: .white, bgColor: Color(red: 62/255, green: 63/255, blue: 70/255), icon: "wand.and.rays").padding()Text("Perfect for teams with 20 members").font(.system(.caption, design: .rounded)).fontWeight(.bold).foregroundStyle(.white).padding(5).background(Color(red: 255/255, green: 183/255, blue: 37/255)).offset(x:0, y: 110)}}Spacer() // 留白}
}#Preview {ContentView()
}struct HeaderView: View {var body: some View {HStack {VStack(alignment: .leading, spacing: 2) {Text("Choose").font(.system(.largeTitle, design: .rounded)).fontWeight(.black)Text("Your Plan").font(.system(.largeTitle, design: .rounded)).fontWeight(.black)}Spacer()}.padding()}
}struct PricingView: View {var title: Stringvar price: Stringvar textColor: Colorvar bgColor: Colorvar icon: String?var body: some View {VStack{if let icon = icon {Image(systemName: icon).font(.largeTitle).foregroundStyle(textColor)}Text(title).font(.system(.title, design: .rounded)).fontWeight(.black).foregroundStyle(textColor)Text(price).font(.system(size: 40,weight: .heavy, design: .rounded)).foregroundStyle(textColor)Text("pre month").font(.headline).foregroundStyle(textColor)}.frame(minWidth: 0, maxWidth: .infinity,minHeight: 100) // 自定义尺寸.padding(40).background(bgColor).clipShape(RoundedRectangle(cornerRadius: 10)) // 裁剪成圆角矩形}
}

效果

作业

//
//  HomeWork.swift
//  SwiftUIStacks
//
//  Created by CHEN Hao on 2024/5/7.
//import SwiftUIstruct HomeWork: View {var body: some View {ZStack{PricingView(title: "Basic", price: "$9", textColor: .white, bgColor: Color(.purple), icon: "mic.circle").padding().offset(x:0,y: 180)PricingView(title: "Pro", price: "$19", textColor: .white, bgColor: Color(.orange), icon: "message").padding().scaleEffect(0.95)PricingView(title: "Team", price: "$299", textColor: .white, bgColor: Color(red: 62/255, green: 63/255, blue: 70/255), icon: "wand.and.rays").padding().scaleEffect(0.90).offset(x:0, y:-180)}}
}#Preview {HomeWork()
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/28688.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

使用 docker-compose 部署 nexus

本篇博客主要介绍如何通过 docker-compose 快速搭建 nexus 服务,毕竟目前采用容器化部署是一件更加快速轻松的方案。 之前的博客已经介绍过 nexus 的搭建,以及为 IDEA 和 Visual Studio 提供代理服务,这里就不详细介绍了,提供出之前博客的链接。 nexus 在 windows 上的搭建…

第一次冲刺

入围+1,这是当时的截图我们暂时完成的功能就是注册登录和主页面的对话,后续我们下一阶段会完成历史对话记录,语音对话等功能 我们第一阶段分工占比:

简述Linux系统内核的作用

本文简述了Linux内核的5个子系统:进程调度(SCHED)、内存管理(MM)、虚拟文件系统(VFS)、网络接口(NET)和进程间通信(IPC)V 1.0 2024年5月7日 发布于博客园目录Linux内核的组成部分进程调度(SCHED)内存管理(MM)虚拟文件系统(VFS)网络接口(NET)进程间通信(IPC…

Spring SpringMVC概述

SpringMVC框架主要用于跟客户端交互,包括请求和响应。前端控制器的作用就是把一些功能封装,我们在开发时就不用再写一些繁杂的代码了 SpringMVC使用DispatcherServlet作为前端控制器,DispatcherServlet本质其实是一个Servlet原先我们在访问时,客户端发起请求直接找Servlet。…

物流行业新篇章:数字孪生系统助力仓储物流园区升级

在数字化浪潮的推动下,物流行业正迎来前所未有的变革,现代化仓储物流园区数字孪生系统正以其独特的魅力引领着物流行业迈向更加智能、高效的新时代。在数字化浪潮的推动下,物流行业正迎来前所未有的变革,现代化仓储物流园区数字孪生系统正以其独特的魅力引领着物流行业迈向…

IO一些基础必备知识点

IO编程 IO一些必备知识点 目录IO编程IO一些必备知识点①了解FAT32以及NTFS区别②了解MMU如何将虚拟地址与物理地址转换③请简述Linux内核的作用Linux内核是链接硬件和上层应用的桥梁,通过这个桥梁我们可以直接在上层完成对硬件的操作④Linux系统目录和文件夹的区别⑤库函数与系…

文件IO的学习

FAT32和NTFS文件系统的区别 什么是文件系统? 文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构;即在存储设备上组织文件的方法。 文件系统的作用?数据组织: 文件系统将数据划分为文件和目录(或文件夹),并提供一种层次化的结构来组织这些数据,使用户和…

自定义单链表(非循环)反转的基本函数接口

题干struct ListNode* ReverseList(struct ListNode* head ) {if (head == NULL||head->next==NULL ) {return head;} else {struct ListNode* Phead=head;struct ListNode* temp=head->next;Phead->next=NULL;Phead=temp;temp=temp->next;while (temp) {Phead->…