美文网首页微信小程序
SwiftUI 精品完成项目之宠物展示与领养App MVVM(

SwiftUI 精品完成项目之宠物展示与领养App MVVM(

作者: iCloudEnd | 来源:发表于2021-03-05 08:56 被阅读0次

    实战需求

    SwiftUI 精品完成项目之宠物展示与领养App

    本文价值与收获

    看完本文后,您将能够作出下面的界面

    home-screen.png home-screen-dark.png details-screen.png details-screen-dark.png Jietu20210303-155225.gif

    看完本文您将掌握的技能

    • 自定义字体
    import SwiftUI
    
    enum SailecFontType: String {
        case bold = "Sailec-Bold"
        case medium = "Sailec-Medium"
        case regular = "Sailec"
    }
    
    struct SailecFont: ViewModifier {
        
        var type: SailecFontType
        var size: CGFloat
        
        init(_ type: SailecFontType = .regular, size: CGFloat = 16) {
            self.type = type
            self.size = size
        }
        
        func body(content: Content) -> some View {
            content.font(Font.custom(type.rawValue, size: size))
        }
    }
    
    • 自定义颜色
    extension Color {
        
        static let main_color = Color("main_color")
        static let primary_color = Color("primary")
        static let secondary_color = Color("secondary")
        static let text_primary_color = Color("text_primary_color")
        static let placeholder_color = Color(UIColor(red: 189/255, green: 189/255, blue: 189/255, alpha: 1.0))
        
        static let red_color = Color(UIColor(red: 235/255, green: 87/255, blue: 87/255, alpha: 1.0))
        static let blue_color = Color(UIColor(red: 0/255, green: 106/255, blue: 246/255, alpha: 1.0))
        
        static let red_color_trans = Color(UIColor(red: 235/255, green: 87/255, blue: 87/255, alpha: 0.1))
        static let blue_color_trans = Color(UIColor(red: 0/255, green: 106/255, blue: 246/255, alpha: 0.1))
        
        init(hex: String, alpha: Double = 1) {
            var cString: String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
            if (cString.hasPrefix("#")) { cString.remove(at: cString.startIndex) }
            
            let scanner = Scanner(string: cString)
            scanner.currentIndex = scanner.string.startIndex
            var rgbValue: UInt64 = 0
            scanner.scanHexInt64(&rgbValue)
            let r = (rgbValue & 0xff0000) >> 16
            let g = (rgbValue & 0xff00) >> 8
            let b = rgbValue & 0xff
            self.init(.sRGB, red: Double(r) / 0xff, green: Double(g) / 0xff, blue:  Double(b) / 0xff, opacity: alpha)
        }
    }
    

    基础知识

    相关文章

      网友评论

        本文标题:SwiftUI 精品完成项目之宠物展示与领养App MVVM(

        本文链接:https://www.haomeiwen.com/subject/hmnqqltx.html