內(nèi)蒙古住房和建設(shè)廳網(wǎng)站網(wǎng)站的內(nèi)連接如何做
鶴壁市浩天電氣有限公司
2026/01/22 10:18:00
內(nèi)蒙古住房和建設(shè)廳網(wǎng)站,網(wǎng)站的內(nèi)連接如何做,如何自己做網(wǎng)站手機(jī)軟件,做陌陌網(wǎng)站什么做SwiftUI入門天氣的靜態(tài)網(wǎng)頁(yè) 一.SwiftUI知識(shí)點(diǎn)1. 自定義文本視圖創(chuàng)建表單2. 添加導(dǎo)航欄3. 修改程序狀態(tài)4. 狀態(tài)綁定UI控件5. 循環(huán)創(chuàng)建視圖 二.天氣網(wǎng)頁(yè) 一.SwiftUI知識(shí)點(diǎn)
1. 自定義文本視圖創(chuàng)建表單
通過 TextField 、 Text 、 Form 組合創(chuàng)建表單#xff0c; Form 自動(dòng)優(yōu)化布…SwiftUI入門天氣的靜態(tài)網(wǎng)頁(yè)一.SwiftUI知識(shí)點(diǎn)1. 自定義文本視圖創(chuàng)建表單2. 添加導(dǎo)航欄3. 修改程序狀態(tài)4. 狀態(tài)綁定UI控件5. 循環(huán)創(chuàng)建視圖二.天氣網(wǎng)頁(yè)一.SwiftUI知識(shí)點(diǎn)1. 自定義文本視圖創(chuàng)建表單通過 TextField 、 Text 、 Form 組合創(chuàng)建表單 Form 自動(dòng)優(yōu)化布局用 Section 拆分內(nèi)容實(shí)現(xiàn)結(jié)構(gòu)化展示。importSwiftUIstructFormDemo:View{StateprivatevarinputTextvarbody:someView{Form{TextField(請(qǐng)輸入內(nèi)容,text:$inputText)Text(已輸入(inputText))}}}#Preview{FormDemo()}2. 添加導(dǎo)航欄用 NavigationStack iOS16/ NavigationView 加導(dǎo)航欄通過 navigationTitle 設(shè)標(biāo)題適配頁(yè)面導(dǎo)航需求。importSwiftUIstructContentView:View{varbody:someView{NavigationStack{Text(表單頁(yè)面).navigationTitle(我的表單).navigationBarTitleDisplayMode(.inline)}}}3. 修改程序狀態(tài)State 管理視圖臨時(shí)狀態(tài)變量值變化時(shí)視圖自動(dòng)刷新適用于單個(gè)視圖內(nèi)的狀態(tài)存儲(chǔ)如輸入內(nèi)容、開關(guān)狀態(tài)。importSwiftUIstructStateDemo:View{Stateprivatevarcount0varbody:someView{VStack{Text(計(jì)數(shù)(count)).font(.title)Button(加1){count1}}.padding()}}#Preview{StateDemo()}4. 狀態(tài)綁定UI控件用 $ 符號(hào)綁定 State 變量與UI控件實(shí)現(xiàn)數(shù)據(jù)實(shí)時(shí)同步例 TextField 輸入直接更新綁定的變量。水煮魚:12-1222:06:06importSwiftUIstructContentView:View{StateprivatevarinputTextvarbody:someView{TextField(請(qǐng)輸入內(nèi)容,text:$inputText).padding().border(Color.gray)Text(你輸入的內(nèi)容(inputText))}}5. 循環(huán)創(chuàng)建視圖ForEach 遍歷數(shù)據(jù)集合動(dòng)態(tài)生成視圖需指定 id 標(biāo)識(shí)數(shù)據(jù)適合重復(fù)視圖如列表的快速創(chuàng)建。importSwiftUIstructForEachDemo:View{letdata[內(nèi)容1,內(nèi)容2,內(nèi)容3]varbody:someView{VStack{ForEach(data,id:.self){textinText(text)}}}}#Preview{ForEachDemo()}二.天氣網(wǎng)頁(yè)importSwiftUIstructContentView:View{varbody:someView{LinearGradient(gradient:Gradient(colors:[Color(#colorLiteral(red:0.2392156869,green:0.6745098233,blue:0.9686274529,alpha:1)),Color(#colorLiteral(red:0.1764705926,green:0.4980392158,blue:0.7568627596,alpha:1))]),startPoint:.top,endPoint:.bottom).edgesIgnoringSafeArea(.all).overlay(VStack(spacing:20){// 頂部城市日期VStack{Text(武漢市).font(.system(size:32,weight:.bold)).foregroundColor(.white)Text(2025年12月12日 星期五).font(.system(size:16)).foregroundColor(.white.opacity(0.8))}.padding(.top,50)// 中間天氣圖標(biāo)溫度天氣狀態(tài)VStack(spacing:15){Image(systemName:sun.max.fill).resizable().aspectRatio(contentMode:.fit).frame(width:120,height:120).foregroundColor(.yellow)Text(28°).font(.system(size:80,weight:.light)).foregroundColor(.white)Text(晴).font(.system(size:24)).foregroundColor(.white)}.padding(.vertical,30)// 底部濕度/風(fēng)速/氣壓卡片HStack(spacing:25){// 濕度卡片VStack(spacing:8){Text(濕度).font(.system(size:14)).foregroundColor(.white.opacity(0.8))Text(65%).font(.system(size:22,weight:.semibold)).foregroundColor(.white)}.frame(width:80,height:80).background(Color.white.opacity(0.2)).cornerRadius(12)// 風(fēng)速卡片VStack(spacing:8){Text(風(fēng)速).font(.system(size:14)).foregroundColor(.white.opacity(0.8))Text(3m/s).font(.system(size:22,weight:.semibold)).foregroundColor(.white)}.frame(width:80,height:80).background(Color.white.opacity(0.2)).cornerRadius(12)// 氣壓卡片VStack(spacing:8){Text(氣壓).font(.system(size:14)).foregroundColor(.white.opacity(0.8))Text(1012hPa).font(.system(size:22,weight:.semibold)).foregroundColor(.white)}.frame(width:80,height:80).background(Color.white.opacity(0.2)).cornerRadius(12)}Spacer()})}}structContentView_Previews:PreviewProvider{staticvarpreviews:someView{ContentView().previewDevice(PreviewDevice(rawValue:iPhone 15 Pro)).previewLayout(.fixed(width:393,height:852))}}