SettingsView/设置页 的实现

news/2024/7/20 22:09:02 标签: iOS, Swift, App, Crypto

1. 创建设置视图 SettingsView.swift

Swift">import SwiftUI

/// 设置页面
struct SettingsView: View {
    /// 环境变量,呈现方式:显示或者关闭
    @Environment(\.presentationMode) var presentationMode
    /// 默认网址
    let defaultURL = URL(string: "https://www.google.com.hk")!
    // https://www.youtube.com/c/swiftfulthinking
    let youtubeURL = URL(string: "https://www.youtube.com")!
    // https://www.buymeacoffee.com/nicksarno
    let coffeeURL = URL(string: "https://www.buymeacoffee.com")!
    /// 交易货币网址
    let coingeckoURL = URL(string: "https://www.coingecko.com")!
    /// 个人网站 https://www.nicksarno.com
    let personalURL = URL(string: "https://blog.csdn.net/u011193452")!
    
    var body: some View {
        NavigationView {
            ZStack {
                // 背景
                Color.theme.background
                    .ignoresSafeArea()
                // 内容
                List {
                    // 应用介绍及网址 部分
                    swiftfulThinkingSection
                        .listRowBackground(Color.gray.opacity(0.2))
                        //.listRowBackground(Color.theme.background.opacity(0.5))
                    // 交易货币介绍及网址 部分
                    coinGeckoSection
                        .listRowBackground(Color.gray.opacity(0.2))
                    // 开发者及网址 部分
                    developerSection
                        .listRowBackground(Color.gray.opacity(0.2))
                    // 应用网址 部分
                    applicationSection
                        .listRowBackground(Color.gray.opacity(0.2))
                }
                .modifier(ListBackgroundModifier())
            }
            .font(.headline)
            .accentColor(.blue)
            .listStyle(.grouped)
            .navigationTitle("Settings")
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading) {
                    XMarkButton(presentationMode: presentationMode)
                }
            }
        }
    }
}

extension SettingsView{
    /// 应用介绍及网址 部分
    private var swiftfulThinkingSection: some View{
        Section {
            VStack(alignment: .leading) {
                Image("logo")
                    .resizable()
                    .frame(width: 100, height: 100)
                    .clipShape(RoundedRectangle(cornerRadius: 20))
                Text("This app was made by following a @SwiftfulThinking course on YouTube. It uses MVVM Architecture, Combine, and CoreData!")
                    .font(.callout)
                    .fontWeight(.medium)
                    .foregroundColor(Color.theme.accent)
            }
            .padding(.vertical)
            // 跳转网址
            Link("Subscribe on YouTube 🎉", destination: youtubeURL)
            Link("Support his coffee addiction ☕️", destination: coffeeURL)
        } header: {
            Text("Swiftful Thinking")
        }
    }
    
    /// 交易货币介绍及网址 部分
    private var coinGeckoSection: some View{
        Section {
            VStack(alignment: .leading) {
                Image("coingecko")
                    .resizable()
                    .scaledToFit()
                    .frame(height: 100)
                    .clipShape(RoundedRectangle(cornerRadius: 20))
                Text("The cryptocurrency data that is used in this app comes from a free API from CoinGecko! Prices may be slightly delayed.")
                    .font(.callout)
                    .fontWeight(.medium)
                    .foregroundColor(Color.theme.accent)
            }
            .padding(.vertical)
            // 跳转网址
            Link("Visit CoinGecko 🦎", destination: coingeckoURL)
        } header: {
            Text("CoinGecko")
        }
    }
    
    /// 开发者及网址 部分
    private var developerSection: some View{
        Section {
            VStack(alignment: .leading) {
                Image("logo-transparent")
                    .resizable()
                    .frame(width: 100, height: 100)
                    .clipShape(RoundedRectangle(cornerRadius: 20))
                Text("This app was developed by Nick. It uses SwiftUI and is written 100% in Swift. The project benefits from multi-threading, publishers/subscribers, and data persistance.")
                    .font(.callout)
                    .fontWeight(.medium)
                    .foregroundColor(Color.theme.accent)
            }
            .padding(.vertical)
            
            // 跳转网址
            Link("Visit Website 🤙", destination: personalURL)
        } header: {
            Text("Developer")
        }
    }
    
    /// 应用网址 部分
    private var applicationSection: some View{
        Section {
            // 跳转网址
            Link("Terms of Service", destination: defaultURL)
            Link("Privacy Policy", destination: defaultURL)
            Link("Company Website", destination: defaultURL)
            Link("Learn More", destination: defaultURL)
        } header: {
            Text("Application")
        }
    }
}

/// 适配 iOS 16 ListView 背景修改问题
struct ListBackgroundModifier: ViewModifier {
    @ViewBuilder
    func body(content: Content) -> some View {
        if #available(iOS 16.0, *) {
            content.scrollContentBackground(.hidden)
        } else {
            content
        }
    }
}

struct SettingsView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsView()
    }
}

2. 效果图:


http://www.niftyadmin.cn/n/5083176.html

相关文章

用AIGC做私活真的太赚了...

说个小道消息,传统涨薪跳槽旺季即将结束,使用AIGC技术已然迎接私活的高潮期!各行业对【AIGC】的需求在短时间内暴增。 估计圈子里的朋友都不会闲着,会趁着旺季赚一笔。 所以,近段时间知识星球很多粉丝朋友收到了很多…

c++视觉处理---Scharr滤波器

Scharr滤波器: cv::Scharr cv::Scharr 是OpenCV库中用于应用Scharr滤波器的函数。Scharr滤波器通常用于图像处理中的边缘检测和特征提取。这是 cv::Scharr 函数的基本用法: cv::Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType);src: 输入…

测开岗学习资料

1.技术栈 测试技术栈 - 简书 2.自动化测试 自动化软件测试技术栈,掌握它,你离大厂不远了 3.测试&测开需具备哪些技术栈?看这篇就够了!(附学习资源!)_资源分享_牛客网 开发转测试&#…

三菱FX5U系列PLC更改运动轴脉冲输出方向控制点的具体方法和步骤详解

三菱FX5U系列PLC更改运动轴脉冲输出方向控制点的具体方法和步骤详解 本例中将轴1的脉冲方向控制点Y4更改为Y16 具体方法可参考以下步骤: 如下图所示,将原来Y4的接线拆下,重新接到Y16端子上(为了安全,建议断电后进行) 将网线一端插到PLC网口,一端连接到电脑上(电脑上无网…

四.镜头知识之放大倍率

四.镜头知识之放大倍率 文章目录 四.镜头知识之放大倍率4.0 前言4.1 镜头的光学放大倍率的计算方法4.2 显示器的电子放大倍率4.2.1 智能硬件产品的显示放大倍率计算案例 4.3 系统放大倍率4.4 智能硬件产品的系统放大倍率计算案例4.4 智能硬件产品的系统放大倍率计算案例 4.0 前…

精品Python的农村振兴平台防贫助农

《[含文档PPT源码等]精品Python的农村振兴平台设计与实现-爬虫》该项目含有源码、文档、PPT、配套开发软件、软件安装教程、项目发布教程等! 软件开发环境及开发工具: 开发语言:python 使用框架:Django 前端技术:J…

SpringBoot注解篇之@Resource与@Autowired

大家好,我是AK,最近在整理Java相关技术知识体系化;本篇主要介绍Resource 注解和 Autowired的区别以及使用,适合学习spring框架小伙伴了解学习。 目录 一、Resource与Autowired的区别二、Resource详解三、Autowired详解 一、Resour…

【喜报】冲量在线荣获首届“创领浦东”创新创业大赛三等奖!

为挖掘和培育更多具有浦东特色的优秀创业代表,深耕人才创新创业沃土。2023年,浦东新区人力资源和社会保障局、浦东新区就业促进中心聚合三大赛事品牌,联手打造升级版赛事IP——首届“创领浦东”创新创业大赛。 经过初选、复选、决赛三轮评审…