Skip to content

Instantly share code, notes, and snippets.

View vince19972's full-sized avatar
🐔

Vince MingPu Shao vince19972

🐔
View GitHub Profile
@vince19972
vince19972 / SwiftUI_borderStyle.swift
Created September 9, 2019 23:24
Demo code of styling border in SwiftUI
// --snip--
renderView = AnyView(configuration.label
.background(backgroundColor!)
.frame(width: iconSize!.rawValue, height: iconSize!.rawValue, alignment: .center)
.clipShape(RoundedRectangle(cornerRadius: iconSize!.rawValue))
.overlay(RoundedRectangle(cornerRadius: iconSize!.rawValue)
.stroke(borderStyle!.color, lineWidth: borderStyle!.width))
)
@vince19972
vince19972 / SwiftUI_mutatingFunc.swift
Created September 9, 2019 23:22
Demo code of building modifier by mutating function in SwiftUI
// buttonLabel modifier
struct TokenButtonLabel: View {
// --snip--
/// State properties
var isHighlighted = false
// --snip--
}
extension TokenButtonLabel {
@vince19972
vince19972 / SwiftUI_tokenButton.swift
Created September 9, 2019 23:15
Demo code of building token button in SwiftUI
struct TokenButton {
var buttonLabel: TokenButtonLabel
var buttonStyle: TokenButtonStyle
// Circle Button
private var circleBtnType: CircleBtnType! = .primary
private var circleBtnIcon: String! = "circle-plus"
init(circleButtonType: CircleBtnType, buttonIcon: String) {
// --snip--
}
@vince19972
vince19972 / SwiftUI_buttonStyle.swift
Last active September 9, 2019 23:18
Demo code of buttonStyle in SwiftUI
struct TokenButtonStyle: ButtonStyle {
/// Global properties
private let styleType: StyleType
private var iconSize: TokenButton.IconSize?
private var backgroundColor: Color?
private var borderStyle: StyleAlias.BorderStyle?
private var textColor: Color?
/// Circle Icon Button
init(iconSize: TokenButton.IconSize,
@vince19972
vince19972 / SwiftUI_buttonLabel.swift
Created September 9, 2019 23:11
Demo code of button label in SwiftUI
struct TokenButtonLabel: View {
/// Global properties
private let labelType: LabelTypes
private var iconName: String?
// Icon Type
private var iconSize: TokenButton.IconSize?
init(name: String, iconSize: TokenButton.IconSize) {
self.labelType = .icon
self.iconName = name
@vince19972
vince19972 / SwiftUI_envSetting.swift
Created September 9, 2019 23:05
Demo code of environment settings and font in SwiftUI
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.environment(\.font, Font.Typography.mainFont)
.environment(\.colorScheme, .dark)
}
}
#endif
@vince19972
vince19972 / SwiftUI_colorFontExtension.swift
Created September 9, 2019 23:03
Demo code of extending color and font in SwiftUI
struct TokenColor {
// --snip--
// see here for more: https://gist.github.com/vince19972/70eee7d66735739aa31567efd7a0a475
}
struct TokenTypography {
// --snip--
// see here for more: https://gist.github.com/vince19972/8ff8635bdb7bfdf54b85ab711b55f634l
}
// extend from native `Color` and `Font` struct
@vince19972
vince19972 / SwiftUI_structColor.swift
Created September 9, 2019 15:03
Demo code of building color palette system in SwiftUI
struct BaseColor {
/// dynamic color sets (with dark and light mode)
let contrastPrimary = Color("contrastPrimary")
let themePrimary = Color("themePrimary")
/// staic color sets (not updating along with color mode)
let darkPrimary = Color("darkPrimary")
let lightPrimary = Color("lightPrimary")
}
@vince19972
vince19972 / SwiftUI_enumTypography.swift
Last active September 12, 2019 22:34
Demo code of building typography system in SwiftUI
struct TokenTypography {
// 1. Prepare base materials
/// a. Level 1 base settings
private enum FontSize: CGFloat {
case
small = 12,
medium = 17,
large = 28