Skip to content

Instantly share code, notes, and snippets.

View lawreyios's full-sized avatar
🎯
Focusing

Lawrence Tan lawreyios

🎯
Focusing
View GitHub Profile
<script>
var redirectToApp = function () {
setTimeout(function appNotInstalled() {
window.location.replace("[Somewhere else like your youtube ad]");
}, 100);
window.location.replace("[iOS App Store URL]");
}; if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
window.location.replace("[iOS App Store URL]");
} else if (/android/i.test(navigator.userAgent)) {
window.location.replace("[Android Play Store URL]");
struct ContentView: View {
@State private var shouldShowErrorLabel = false
init() {
UINavigationBar.appearance().backgroundColor = .blue
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor : UIColor.white,
]
}
extension AnyTransition {
static var fadeAndSlide: AnyTransition {
AnyTransition.opacity.combined(with: .move(edge: .top))
}
}
struct ContentView: View {
let itemsForSale = [
Item(id: 1, title: "Mask", price: 5.0, description: "A mask is an object normally worn on the face, typically for protection, disguise, performance, or entertainment. ... They are usually worn on the face, although they may also be positioned for effect elsewhere on the wearer's body", onSale: true),
Item(id: 2, title: "Sanitizer", price: 15.0, description: "Hand sanitiser, hand antiseptic, hand disinfectant, hand rub, handrub. Hand sanitizer is a liquid, gel, or foam generally used to decrease infectious agents on the hands.", onSale: false),
Item(id: 3, title: "Vitamin", price: 25.0, description: "Vitamins are nutrients your body needs to develop and function properly. There are 13 essential vitamins: A, D, E, and K, which are fat-soluble, and vitamins C and the B-complex group, which are water-soluble. Each vitamin has a distinct role in keeping you healthy.", onSale: false),
]
var body: some View {
Scroll
struct CardView: View {
var title: String
var description: String
var price: Double
var isOnSale: Bool
private let cardHeight: CGFloat = 300.0
private let cardWidth: CGFloat = 200.0
struct Item: Identifiable {
var id: Int
var title: String
var price: Double
var description: String
var onSale: Bool
}
struct ModalView: View {
var body: some View {
NavigationView {
VStack {
Spacer()
Text("ModalView")
Spacer()
}.modifier(RedNavigationBar(title: "Modal"))
}
}
struct RedNavigationBar: ViewModifier {
var title: String
func body(content: Content) -> some View {
content
.navigationBarColor(.red, textColor: .white)
.navigationBarTitle(title)
}
}
extension View {
func navigationBarColor(_ backgroundColor: UIColor?, textColor: UIColor?) -> some View {
modifier(NavigationBarModifier(backgroundColor: backgroundColor, textColor: textColor))
}
}
struct NavigationBarModifier: ViewModifier {
var backgroundColor: UIColor?
var textColor: UIColor?
struct ContentView: View {
@ObservedObject var viewModel = ContentViewModel()
var genderSegmentedControl: some View {
Picker("", selection: $viewModel.selectedSegment.onChange(sectionChange)) {
Text("Male").tag(Gender.male.rawValue)
Text("Female").tag(Gender.female.rawValue)
}
.pickerStyle(SegmentedPickerStyle())