- SwiftUI 精品完成项目之宠物展示与领养App MVVM(
- SwiftUI 界面大全之宠物领养管理App(教程含源码)
- SwiftUI iOS 精品项目之 emoji查询和搜索App(
- SwiftUI macOS和iPad精品项目之天气完整App(项
- SwiftUI 精品开源项目之 01 超酷全功能倒计时Count
- SwiftUI 精品完整项目之任务管理todo list App
- iOS 精品完整项目之 Quiz考试类App,遵循 MVC 设计
- SwiftUI 精品之App截屏并微信、相册分享ScrollVi
- SwiftUI 精品完整项目之 使用 SwiftUI 创建的密码
- SwiftUI3 完整项目之 新闻类项目支持Feed流网络请求与
实战需求
SwiftUI 精品完成项目之宠物展示与领养App
本文价值与收获
看完本文后,您将能够作出下面的界面





看完本文您将掌握的技能
- 自定义字体
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)
}
}
网友评论