Skip to content

Instantly share code, notes, and snippets.

struct ContentView: View {
let collums = [
/// define number of caullum here
GridItem(.flexible()),
GridItem(.flexible())
]
var body: some View {
ScrollView(.vertical) { //set .horizontal to scroll horizontally
LazyVGrid(columns: collums) { // use HGrid to layout horizontally
ForEach(0...50, id: \.self) { i in
import SwiftUI
struct Row {
var value: Int
init(value: Int) {
print("INIT: \(value)") // see init calls with scroll in case of lazy loading
self.value = value
}
}
import SwiftUI
struct Chips: View {
let systemImage: String //pass system image
let titleKey: LocalizedStringKey //text or localisation value
@State var isSelected: Bool
var body: some View {
HStack {
Image.init(systemName: systemImage).font(.title3)
Text(titleKey).font(.title3).lineLimit(1)
}.padding(.all, 10)
import SwiftUI
struct ChipsContent: View {
@ObservedObject var viewModel = ChipsViewModel()
var body: some View {
var width = CGFloat.zero
var height = CGFloat.zero
return GeometryReader { geo in
ZStack(alignment: .topLeading, content: {
ForEach(viewModel.dataObject) { chipsData in //loop to render all chips
Chips(systemImage: chipsData.systemImage,
//
// ContentView.swift
// ios14-demo
//
// Created by Prafulla Singh on 23/6/20.
//
import SwiftUI
struct ChipsDataModel: Identifiable {
let id = UUID()
// Created by Prafulla Singh on 23/6/20.
//
import SwiftUI
struct ContentView: View {
var body: some View {
ScrollView {
LazyHStack {
PageView()
}
@prafullakumar
prafullakumar / CollapsibleList.swift
Last active June 30, 2020 02:07
ios -14 Collapsible List
// Created by Prafulla Singh on 29/6/20.
//
import SwiftUI
struct FamilyTree: Identifiable {
let id = UUID()
let name: String
let childrens: [FamilyTree]?
}
import SwiftUI
struct StickyLayoutGrid: View {
let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 3)
var body: some View {
NavigationView {
ScrollView(.vertical) { //set .horizontal to scroll horizontally
///pinnedViews: [.sectionHeaders] => set header or footer you want to pin. if do not want to pin leave empty, sectionFooters => for sticky footer
LazyVGrid(columns: columns, spacing: 10, pinnedViews: [.sectionHeaders]) {
Section(header: headerView(type: "Grid")) {
ForEach(0..<10) { i in
import SwiftUI
import os
@main
struct ios14DemoApp: App {
@StateObject var notificationCenter = NotificationCenter()
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
struct PhotoPicker: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> PHPickerViewController {
//init PHPickerViewController here
}
func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {
}