import SwiftUI
struct DesignCode: View {
@State var show = false
@State var viewState = CGSize.zero
var body: some View {
ZStack {
TitleView()
.blur(radius: show ? 20 : 0)
CardBottomView()
.blur(radius: show ? 20 : 0)
.animation(.default)
CardView()
.background(show ? Color.red : Color.blue)
.cornerRadius(10)
.shadow(radius: 20 )
.offset(x: 0, y: show ? -400 : -40)
.scaleEffect(0.85)
.rotationEffect(Angle(degrees: show ? 15.0 : 0))
//.rotation3DEffect(Angle(degrees: show ? 50 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
.blendMode(.hardLight)
.animation(.easeInOut(duration: 0.7))
.offset(x: viewState.width, y: viewState.height)
CardView()
.background(show ? Color.red : Color.yellow)
.cornerRadius(10)
.shadow(radius: 20 )
.offset(x: 0, y: show ? -200 : -20)
.scaleEffect(0.9)
.rotationEffect(Angle(degrees: show ? 10.0 : 0))
//.rotation3DEffect(Angle(degrees: show ? 40 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
.blendMode(.hardLight)
.animation(.easeInOut(duration: 0.5))
.offset(x: viewState.width, y: viewState.height)
CertificateView()
.offset(x: viewState.width, y: viewState.height)
.scaleEffect(0.95)
.rotationEffect(Angle(degrees: show ? 5.0 : 0))
//.rotation3DEffect(Angle(degrees: show ? 30 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
.animation(.spring())
.onTapGesture {
self.show.toggle()
}
.gesture(
DragGesture()
.onChanged { value in
self.viewState = value.translation
self.show = true
}
.onEnded { value in
self.viewState = CGSize.zero
self.show = false
}
)
}
}
}
struct DesignCode_Previews: PreviewProvider {
static var previews: some View {
DesignCode()
}
}
struct CardView: View {
var body: some View {
VStack {
Text("hhdshfs")
}
.frame(width: 340.0, height: 300.0)
.offset(x: 0, y: -20)
}
}
struct CertificateView: View {
var body: some View {
VStack {
HStack {
VStack(alignment:.leading) {
Text("UI Design")
.font(.largeTitle)
Text("Certificate")
}
Spacer()
Image("c4")
.resizable()
.frame(width: 30, height: 30)
}
.padding(.horizontal)
Spacer()
Image("1-1")
}
.frame(width: 340.0, height: 300.0)
.background(Color.blue)
.cornerRadius(10)
.shadow(radius: 20)
}
}
struct TitleView: View {
var body: some View {
VStack {
HStack {
Text("Certificates")
.font(.largeTitle)
Spacer()
}
Image("c1-1")
.resizable()
.frame(width: 100, height:100)
Spacer()
}
.padding()
}
}
struct CardBottomView: View {
var body: some View {
VStack(spacing:20) {
Rectangle()
.frame(width: 60, height: 6)
.cornerRadius(3.0)
.opacity(0.2)
Text("fgdshghsfdskguydiassf asiuy usaotufsdiua asfusiuga euituaosgfu ias fusiu fgaisugia uasdiguaisg UFDIugfoa effet")
.lineLimit(10)
Spacer()
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.padding(.horizontal)
.background(Color.white)
.cornerRadius(30)
.shadow(radius: 20)
.offset(y: 600)
}
}
import SwiftUI
struct Home: View {
//var menuItems = ["My Account", "Billing", "Team", "Sign out"]
@State var show = false
@State var showProfile = false
var body: some View {
ZStack {
HomeList()
.blur(radius: show ? 20 : 0)
.scaleEffect(showProfile ? 0.95 : 1)
.animation(.default)
DesignCode()
.background(Color.white)
.cornerRadius(30)
.shadow(radius: 20)
.animation(.interactiveSpring())
.offset(y: showProfile ? 45 : UIScreen.main.bounds.height)
MenuButton(show: $show)
.offset(x: -30, y: showProfile ? 0 : 80)
.animation(.spring())
MenuRight(show: $showProfile)
.offset(x: -16, y: showProfile ? 0 : 88)
.animation(.spring())
MenuView(show: $show)
}
}
}
struct Home_Previews: PreviewProvider {
static var previews: some View {
Home()
}
}
struct MenuRow: View {
var image = "creditcard"
var text = "My Account"
var body: some View {
HStack {
Image(systemName: image)
.imageScale(.large)
.foregroundColor(.blue)
.frame(width:32,height: 32)
Text(text)
.font(.headline)
Spacer()
}
}
}
struct Menu : Identifiable {
var id = UUID()
var title : String
var icon : String
}
let menuData = [
Menu(title: "My Account", icon: "person.crop.circle"),
Menu(title: "Billing", icon: "creditcard"),
Menu(title: "Team", icon: "person.and.person"),
Menu(title: "Sign out", icon: "arrow.uturn.down")
]
struct MenuView: View {
var menu = menuData
@Binding var show: Bool
var body: some View {
VStack(alignment: .leading, spacing: 20) {
ForEach(menu) { item in
MenuRow(image: item.icon, text: item.title)
}
Spacer()
}
.padding(.top, 20)
.padding(30)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.white)
.cornerRadius(30)
.padding(.trailing, 60)
.shadow(radius: 20 )
.rotation3DEffect(Angle(degrees: show ? 0 : 60), axis: (x: 0, y: 10.0, z: 0))
.animation(.default)
.offset(x: show ? 0 : -UIScreen.main.bounds.width)
.onTapGesture {
self.show.toggle()
}
}
}
struct CircleButton: View {
var icon = "person.crop.circle"
var body: some View {
HStack {
Image(systemName: icon)
.foregroundColor(.black)
}
.frame(width: 44, height: 44)
.background(Color.white)
.cornerRadius(30)
.shadow(color: .black, radius: 10, x: 0.0, y: 10)
}
}
struct MenuButton: View {
@Binding var show: Bool
var body: some View {
ZStack {
Button(action: { self.show.toggle()}) {
HStack {
Spacer()
Image(systemName: "list.dash")
.foregroundColor(.black)
}
.padding(.trailing, 20)
.frame(width: 90, height: 60)
.background(Color.white)
.cornerRadius(30)
.shadow(color: .black, radius: 10, x: 0.0, y: 10)
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity,alignment: .topLeading)
}
}
struct MenuRight: View {
@Binding var show: Bool
var body: some View {
ZStack {
HStack {
Button(action: { self.show.toggle()}) {
CircleButton(icon: "person.crop.circle")
}
Button(action: { self.show.toggle()}) {
CircleButton(icon: "bell")
}
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity,alignment: .topTrailing)
}
}
import SwiftUI
struct UpdateList: View {
var updates = updateData
@ObservedObject var store = UpdateStore(updates: updateData)
func addUpdate() {
store.updates.append(Update(image: "c1", title: "New title", text: "djsf", date: "22"))
}
func move(from source: IndexSet, to destination: Int) {
store.updates.move(fromOffsets: source, toOffset: destination)
}
var body: some View {
NavigationView {
VStack {
List {
ForEach(store.updates) { item in
NavigationLink(destination: UpdateDetail(title:item.title, text: item.text, image: item.image)) {
HStack(spacing: 12) {
Image(item.image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 80, height: 80)
.cornerRadius(20)
VStack(alignment: .leading) {
Text(item.title)
.font(.headline)
Text(item.text)
.lineLimit(2)
.lineSpacing(4)
.font(.subheadline)
.frame(height: 50)
Text(item.date)
.font(.caption)
.fontWeight(.bold)
.foregroundColor(.gray)
}
}
.padding(30)
}
}
.onDelete { index in
self.store.updates.remove(at: index.first!)
}
.onMove(perform: move)
}
.navigationTitle(Text("Updates"))
.navigationBarItems(
leading: Button(action: addUpdate, label: {
Image(systemName: "plus")
})
,trailing:
EditButton()
)
}
}
}
}
struct UpdateList_Previews: PreviewProvider {
static var previews: some View {
UpdateList()
}
}
struct Update: Identifiable {
var id = UUID()
var image: String
var title: String
var text: String
var date: String
}
let updateData = [
Update(image: "c1", title: "Swift UI", text: "learn how to build", date: "JUN 26"),
Update(image: "c1", title: "Frs d g g d h g d", text: "ggh gdgthd", date: "JUN 11"),
Update(image: "c1", title: "fhgdfk fdgs dgg f", text: "gfs fs gfa", date: "JUN 2"),
Update(image: "c1", title: "hgh dfgsa a f gf d", text: "leg gfs f dd gg", date: "JUN 6")
]
import SwiftUI
struct Settings: View {
@State var receive = false
@State var number = 11
@State var selection = 2
@State var date = Date()
@State var email = ""
@State var submit = false
var body: some View {
NavigationView {
Form {
Toggle(isOn: $receive) {
Text("hh")
}
Stepper(value: $number, in: 1...12) {
Text("\(number) kk\(number > 1 ? "s" : "")")
}
Picker(selection: $selection, label: Text("This is a Picker")) {
Text("Picker1").tag(1)
Text("Picker2").tag(2)
}
DatePicker(selection: $date, label: { Text("This is a Date") })
Section(header: Text("Email")) {
TextField("Placeholder", text: $email)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
Button(action: {self.submit.toggle()}, label: {
Text("Submit")
})
.alert(isPresented: $submit, content: {
Alert(title: Text("Thanks"), message: Text("Email:\(email)"))
})
}
.navigationBarTitle("Settings")
}
}
}
struct Settings_Previews: PreviewProvider {
static var previews: some View {
Settings()
}
}
import SwiftUI
struct TabBar: View {
var body: some View {
TabView (selection: .constant(1)){
Home()
.tabItem ({
Image(systemName: "photo")
Text("Home")
})
.tag(1)
DesignCode()
.tabItem ({
Image(systemName: "photo")
Text("Certificates")
})
.tag(2)
Settings()
.tabItem ({
Image(systemName: "photo")
Text("Settings")
})
.tag(3)
}
}
}
struct TabBar_Previews: PreviewProvider {
static var previews: some View {
Group {
TabBar()
TabBar()
.environment(\.colorScheme, .dark)
.environment(\.sizeCategory, .extraExtraLarge)
}
}
}
import SwiftUI
import Combine
class UpdateStore: ObservableObject {
var didChange = PassthroughSubject<Void, Never>()
@Published var updates: [Update] {
didSet {
didChange.send()
}
}
init(updates: [Update] = []) {
self.updates = updates
}
}
import SwiftUI
struct UpdateDetail: View {
var title = "sdfg"
var text = "fdgf"
var image = "c1"
var body: some View {
VStack {
Text(title)
.font(.largeTitle)
.fontWeight(.heavy)
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 200, height: 200)
Text(text)
.lineLimit(nil)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
Spacer()
}
.padding(30)
}
}
struct UpdateDetail_Previews: PreviewProvider {
static var previews: some View {
UpdateDetail()
}
}
import SwiftUI
struct HomeList: View {
var courses = coursesData
var body: some View {
NavigationView {
VStack {
HStack {
VStack(alignment: .leading) {
Text("Courses")
.font(.largeTitle)
.fontWeight(.heavy)
Text("22 coursess")
.foregroundColor(.gray)
}
Spacer()
}
.padding(.leading, 70)
.padding(.bottom, 40)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing:30) {
ForEach(courses) { item in
NavigationLink(
destination: DesignCode()) {
GeometryReader { geometry in
CourseView(
title: item.title,
image: item.image,
color: item.color,
shadowColor: item.shadowColor)
.rotation3DEffect(Angle(degrees: Double(geometry.frame(in: .global).minX - 40) / -20), axis: (x:0, y: 10.0, z: 0))
}
.frame(width: 246, height: 150)
}
}
}
.padding(.leading, 40)
Spacer()
}
}
.padding(.top, 0)
}
}
}
struct HomeList_Previews: PreviewProvider {
static var previews: some View {
HomeList()
}
}
struct CourseView: View {
var title = "Bulid an app wjsfs g dsfsgfgh "
var image = "c1"
var color = Color("backgroundShadow")
var shadowColor = Color("backgroundShadow")
var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.title)
.fontWeight(.bold)
.foregroundColor(.white)
.padding(30)
.lineLimit(4)
.padding(.trailing, 50)
Spacer()
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 246, height: 200)
.padding(.bottom, 30)
}
.background(color)
.cornerRadius(30)
.frame(width: 245, height: 360)
.shadow(color: shadowColor, radius: 20, x: 0, y: 20)
}
}
struct Course: Identifiable {
var id = UUID()
var title: String
var image: String
var color: Color
var shadowColor: Color
}
let coursesData = [
Course(
title: "Build an app with SwiftUI",
image: "c1",
color: Color("backgroundShadow"),
shadowColor: Color("backgroundShadow")),
Course(
title: "Build dsfhds fgsg dfs",
image: "c1",
color: Color.red,
shadowColor: Color.red),
Course(
title: "Blue an app with blue",
image: "c1",
color: Color.blue,
shadowColor: Color.blue),
]
import Foundation
class ToDo: ObservableObject {
@Published var ToDoList: [SingleToDo]
var count = 0
init() {
self.ToDoList = []
}
init(data: [SingleToDo]) {
self.ToDoList = []
for item in data {
self.ToDoList.append(SingleToDo(title: item.title, duedate: item.duedate, id: self.count))
count += 1
}
}
func check(id: Int) {
self.ToDoList[id].isChecked.toggle()
}
}
struct SingleToDo: Identifiable {
var title: String = ""
var duedate: Date = Date()
var isChecked: Bool = false
var id: Int = 0
}
标签:struct,show,Text,title,swiftui,跳转,var,View,页面
From: https://blog.csdn.net/qq_63007445/article/details/143450952