137 lines
4.6 KiB
Swift
137 lines
4.6 KiB
Swift
//
|
|
// View+Style.swift
|
|
// style扩展
|
|
//
|
|
// Created by CC-star on 2025/6/12.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
extension View{
|
|
|
|
func btnStyle() -> some View{ size15().buttonStyle(.borderless).accent() }
|
|
|
|
func textStyle() -> some View{ size15().tc().lineSpacing(6) }
|
|
func textStyle2() -> some View{ size15().tc2().lineSpacing(6) }
|
|
func oneLineStyleMiddle() -> some View{ lineLimit(1).truncationMode(.middle) }
|
|
func explainStyle() -> some View { size15sb().frame(maxWidth: .infinity, maxHeight: .infinity).padding() }//问题说明性提示文字
|
|
//navi
|
|
func naviBarStyle() -> some View {
|
|
navigationBarTitleDisplayMode(.inline)
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.toolbarBackground(.aBG, for: .navigationBar) }
|
|
|
|
//筛选
|
|
func labelStyleOF() -> some View { tc2().size15semib() }
|
|
func badgeStyle() -> some View { size13().semib().white().padding(6).bgA()//筛选的个数样式
|
|
.clipShape(Circle())//clipShape裁剪成圆形
|
|
}
|
|
|
|
@ViewBuilder func selectBtnStyle(_ selected: Bool) -> some View {//ViewBuilder允许返回不同的视图
|
|
if selected {
|
|
buttonStyle(.borderedProminent)
|
|
} else {
|
|
tint(Color.aTC).buttonStyle(.bordered)
|
|
}
|
|
}
|
|
|
|
|
|
//List里面的东西
|
|
func subTStyle() -> some View{
|
|
size16semib().tc()
|
|
}
|
|
|
|
func subTStyleL() -> some View{
|
|
headline().tc()
|
|
}
|
|
|
|
|
|
|
|
//cell
|
|
func cellPaddingRadius() -> some View{//带radius
|
|
padding(.vertical)
|
|
.padding(.horizontal,12)
|
|
.bg()
|
|
.radius(8)
|
|
}
|
|
func cellOutPadding() -> some View{
|
|
padding([.top,.horizontal],9)
|
|
//.padding(.bottom,10)
|
|
}
|
|
|
|
//list
|
|
func listRowStyle() -> some View{
|
|
listRowInsets(EdgeInsets())
|
|
.listRowSeparator(.hidden)
|
|
.listRowBackground(Color.clear)
|
|
}
|
|
|
|
func listStyle() -> some View{
|
|
listStyle(.inset)
|
|
.scrollContentBackground(.hidden)
|
|
.bg2()
|
|
.environment(\.defaultMinListRowHeight,0) }
|
|
|
|
func listRowStyleLoading2() -> some View {//加载更新数据视图
|
|
padding(.top).padding(.bottom,100).size13sb().push(to: .center).bg2().listRowStyle()
|
|
}
|
|
|
|
//总的
|
|
func cellStyle() -> some View{
|
|
cellPaddingRadius().cellOutPadding().listRowStyle()
|
|
}
|
|
|
|
//Form里面的
|
|
func littleTStyle() -> some View{
|
|
size13().tc2().fontWeight(.light)
|
|
}
|
|
func pStyle() -> some View{
|
|
frame(height: kTFAndPHeight).border(borderColor: Color(.systemGray4))
|
|
}
|
|
func tfStyle() -> some View{//单行
|
|
frame(height: kTFAndPHeight).padding(.horizontal,9).border(borderColor: Color(.systemGray4)).submitLabel(.done)
|
|
}
|
|
func tfStyleMultiS() -> some View{
|
|
lineLimit(1...4).frame(minHeight: kTFAndPHeight).padding(.horizontal,9).border(borderColor: Color(.systemGray4)).lineSpacing(4)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
func tfStyleMultiM() -> some View{
|
|
lineLimit(3...8).frame(minHeight: kTFAndPHeight).padding(.horizontal,9).border(borderColor: Color(.systemGray4)).lineSpacing(4)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
func tfStyleMultiL() -> some View{
|
|
lineLimit(4...10).frame(minHeight: kTFAndPHeight).padding(.horizontal,9).border(borderColor: Color(.systemGray4)).lineSpacing(4)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
func conlonStyle() -> some View{
|
|
bold().padding(.horizontal,2).offset(y: -1)
|
|
}
|
|
func toggleStyle(isTap: Bool) -> some View{
|
|
size15().foregroundStyle(isTap ? .white : .aTC).padding(.horizontal,10).frame(height: kTFAndPHeight)
|
|
.background(isTap ? Color.accent.gradient : Color.bg.gradient).radius()
|
|
.border(borderColor: isTap ? .clear : .accent)
|
|
}
|
|
|
|
func appleStyleS() -> some View{ font(.body).frame(maxWidth: .infinity).padding(.vertical, 6) }
|
|
func appleStyle(disabled: Bool = false) -> some View{
|
|
headline().white().frame(height: 55).frame(maxWidth: .infinity)
|
|
.background(disabled ? Color.secondary.gradient : Color.accent.gradient).radius() }
|
|
func appleStyleP() -> some View{ tint(.white).frame(height: 55).frame(maxWidth: .infinity).background(.accent.gradient).radius() }
|
|
|
|
|
|
//个人页
|
|
//文本
|
|
func loadingJobStyle() -> some View { size13().white().frame(width: 150, height: 25).background(Color.accent.gradient).radius(6) }
|
|
//progress
|
|
func loadingJobStyleP() -> some View { tint(.white).frame(width: 150, height: 25).background(Color.accent.gradient).radius(6) }
|
|
func settingsStyle() -> some View { tc().size16() }
|
|
}
|
|
|
|
|
|
extension Image{
|
|
func iconStyle() -> some View {
|
|
resizable().frame(width: 16, height: 16)
|
|
}
|
|
}
|
|
|