100 lines
3.7 KiB
Swift
100 lines
3.7 KiB
Swift
//
|
|
// View+.swift
|
|
// 样式扩展
|
|
//
|
|
// Created by CC-star on 2025/6/12.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
extension View{
|
|
|
|
//矩形圆角
|
|
func radius(_ radius: CGFloat = 4) -> some View{ clipShape(RoundedRectangle(cornerRadius: radius)) }
|
|
// func radius2(_ radius: CGFloat = 4) -> some View{ clipShape(RoundedRectangle(cornerRadius: radius)) }
|
|
func border(radius: CGFloat = 4, borderColor: Color) -> some View{
|
|
overlay { RoundedRectangle(cornerRadius: radius).strokeBorder(borderColor, lineWidth: 1) }
|
|
}
|
|
|
|
//颜色
|
|
func tc() -> some View{ foregroundStyle(.aTC) }
|
|
func tc2() -> some View{ foregroundStyle(.aTC2) }
|
|
func secondary() -> some View{ foregroundStyle(.secondary) }
|
|
func accent() -> some View{ foregroundStyle(.accent) }
|
|
func white() -> some View{ foregroundStyle(.white) }
|
|
func red() -> some View{ foregroundStyle(.red) }
|
|
func gray() -> some View{ foregroundStyle(.gray) }
|
|
func purple() -> some View{ foregroundStyle(.purple) }
|
|
func bg() -> some View{ background(Color.aBG) }
|
|
func bgA() -> some View{ background(Color.accent) }
|
|
func bg2() -> some View{ background(Color.aBG2) }
|
|
|
|
//字体大小
|
|
func size9() -> some View{ font(.system(size: 9)) }
|
|
func size11() -> some View{ font(.system(size: 11)) }
|
|
func size12() -> some View{ font(.system(size: 12)) }
|
|
func size13() -> some View{ font(.system(size: 13)) }
|
|
func size13s() -> some View{ size13().secondary() }
|
|
func size13sb() -> some View{ size13().secondary().bold() }
|
|
func size14() -> some View{ font(.system(size: 14)) }
|
|
func size15semib() -> some View{ font(.system(size: 15)).semib() }
|
|
func size15() -> some View{ font(.system(size: 15)) }
|
|
func size15sb() -> some View{ font(.system(size: 15)).secondary().bold() }
|
|
func size15pb() -> some View{ font(.system(size: 15)).foregroundStyle(.pink).bold() }
|
|
func size16() -> some View{ font(.system(size: 16)) }
|
|
func size16semib() -> some View{ font(.system(size: 16)).semib() }
|
|
func size17() -> some View{ font(.system(size: 17)) }
|
|
func headline() -> some View{ font(.headline) }
|
|
func size18b() -> some View{ font(.system(size: 18)).bold() }
|
|
func size18ab() -> some View{ font(.system(size: 18)).bold().accent() }
|
|
func size20b() -> some View{ font(.title3).bold() }
|
|
|
|
//字体粗细
|
|
func med() -> some View{ fontWeight(.medium) }
|
|
func semib() -> some View{ fontWeight(.semibold) }
|
|
|
|
func push(to alignment: Alignment) -> some View {
|
|
frame(maxWidth: .infinity, alignment: alignment)
|
|
}
|
|
|
|
//List多行文本必备
|
|
func allowMulti() -> some View{
|
|
fixedSize(horizontal: false, vertical: true).textSelection(.enabled).multilineTextAlignment(.leading)
|
|
}
|
|
//图片相关
|
|
func thumbFrame() -> some View {
|
|
frame(width: 100, height: 100)
|
|
}
|
|
func thumbFrameS(aspectRatio: CGFloat = 1) -> some View {
|
|
frame(width: 40, height: 40 / aspectRatio)
|
|
}
|
|
|
|
}
|
|
|
|
extension Color{
|
|
static let labeBG = Color(.systemFill)
|
|
static let labelBG2 = Color(.systemGray5)
|
|
static let bg = Color.aBG
|
|
static let bg2 = Color.aBG2
|
|
}
|
|
|
|
|
|
// MARK: - 让右滑返回上一页有效
|
|
extension UINavigationController: @retroactive UIGestureRecognizerDelegate {
|
|
override open func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
interactivePopGestureRecognizer?.delegate = self
|
|
}
|
|
|
|
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { return viewControllers.count > 1 }
|
|
|
|
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { true }
|
|
}
|
|
|
|
//收起键盘
|
|
extension UIApplication {
|
|
func hideKeyboard() {
|
|
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
|
}
|
|
}
|