Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct Diamond: Shape {
func path(in rect: CGRect) -> Path {
let (x, y, width, height) = rect.centeredSquare.flatten()
let lowerPoint = CGPoint(x: x + width / 2, y: (y + height ))
let path = Path { p in
p.move(to: lowerPoint)
import SwiftUI
struct Spade: Shape {
func path(in rect: CGRect) -> Path {
let (x, y, width, height) = rect.centeredSquare.flatten()
var heartPath = Heart().rotation(.A180).path(in: CGRect(x: x, y: y, width: width, height: height * 0.9)) //take 10% for bottom rect
let rectPath = Rectangle().path(in: CGRect(x: x + width * 0.4, y: y + height * 0.5, width: width * 0.2, height: height * 0.5))
import SwiftUI
struct Club: Shape {
func path(in rect: CGRect) -> Path {
let (x, y, width, height) = rect.centeredSquare.flatten()
let center = rect.centeredSquare.center
let center1 = CGPoint(x: x + width / 2, y: (y + height/4 ))
let center2 = CGPoint(x: x + width / 4, y: (y + height/2 ))
struct QRCodeDataSet {
let logo: UIImage?
let url: String
let backgroundColor: CIColor
let color: CIColor
let size: CGSize
init(logo: UIImage? = nil, url: String) {
self.logo = logo
self.url = url
private func createCIImage() -> CIImage? {
guard let filter = CIFilter(name: "CIQRCodeGenerator") else {
return nil
}
filter.setDefaults()
filter.setValue(url.data(using: String.Encoding.ascii), forKey: "inputMessage")
filter.setValue("H", forKey: "inputCorrectionLevel")
//https://www.qrcode.com/en/about/error_correction.html
return filter.outputImage
}
private func updateColor(image: CIImage) -> CIImage? {
guard let colorFilter = CIFilter(name: "CIFalseColor") else { return nil }
colorFilter.setValue(image, forKey: kCIInputImageKey)
colorFilter.setValue(color, forKey: "inputColor0")
colorFilter.setValue(backgroundColor, forKey: "inputColor1")
return colorFilter.outputImage
}
private func addLogo(image: CIImage, logo: UIImage) -> CIImage? {
guard let combinedFilter = CIFilter(name: "CISourceOverCompositing") else { return nil }
guard let logo = logo.cgImage else {
return image
}
let ciLogo = CIImage(cgImage: logo)
import SwiftUI
import Foundation
import UIKit
struct ContentView: View {
var body: some View {
ZStack {
QRView().frame(width: 300, height: 300, alignment: .center)
import SwiftUI
struct ContentView: View {
@State private var text = "Test Multiline"
var body: some View {
TextEditor(text: $text)
.padding()
.font(.subheadline)
}
}
import SwiftUI
class Brand: ObservableObject {
var name = "Apple"
var type = "Tech"
}
struct ContentView: View {