Skip to content

Instantly share code, notes, and snippets.

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
@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]?
}
// Created by Prafulla Singh on 23/6/20.
//
import SwiftUI
struct ContentView: View {
var body: some View {
ScrollView {
LazyHStack {
PageView()
}
//
// ContentView.swift
// ios14-demo
//
// Created by Prafulla Singh on 23/6/20.
//
import SwiftUI
struct ChipsDataModel: Identifiable {
let id = UUID()
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,
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 Row {
var value: Int
init(value: Int) {
print("INIT: \(value)") // see init calls with scroll in case of lazy loading
self.value = value
}
}
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
class Brand: ObservableObject {
var name = "Apple"
var type = "Tech"
}
struct ContentView: View {
import SwiftUI
struct ContentView: View {
@State private var text = "Test Multiline"
var body: some View {
TextEditor(text: $text)
.padding()
.font(.subheadline)
}
}