Skip to content

Instantly share code, notes, and snippets.

View kazuhiro4949's full-sized avatar

Kazuhiro Hayashi kazuhiro4949

View GitHub Profile
import SwiftUI
private var menus: [String] = [
"cat",
"car",
"human",
"robot",
"coffee"
]
import SwiftUI
import Combine
// MARK: - Data
class CurrentTime: ObservableObject {
@Published var seconds = Double.zero
private let timer = Timer.publish(every: 0.16, on: .main, in: .common).autoconnect()
private var cancellableSet = Set<AnyCancellable>()
import SwiftUI
struct Data: Identifiable, Equatable {
let id: UUID = .init()
let value: String
}
struct ContentView: View {
@Namespace var namespace
import SwiftUI
struct ContentView: View {
private static let imageHeight: CGFloat = 300
@State private var offset: CGFloat = 0
var body: some View {
ScrollView {
@kazuhiro4949
kazuhiro4949 / one_shot_animated_gif.swift
Last active July 29, 2018 01:55
One shot gif animation with UIImageView.images
import UIKit
import ImageIO
// make one shot gif animation from Gif.
let gif = Gif(with: "GIF File Name (not in asset catalog)")!
let base: Double = 4000
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
// set start image before starting animation
imageView.image = gif.frames.first
//: Playground - noun: a place where people can play
import UIKit
// Cake PatternもどきをSwiftで実装したもの。要するにProtocolのコンポジションによって依存の定義、解決をしていく
protocol Animal {}
struct Cat: Animal {}
class TextView: UITextView {
lazy var moreLabel: UILabel = {
let label = UILabel()
label.text = "さらに表示"
label.textColor = .gray
label.font = self.font
label.textAlignment = .center
return label
}()
@kazuhiro4949
kazuhiro4949 / CharactorAnimation.swift
Created March 21, 2017 14:37
potatotips #37 sample code
hoge
@kazuhiro4949
kazuhiro4949 / PickerKeyboard.swift
Last active January 4, 2019 04:10
Show UIPickerView as "Custom Keyboard"
import UIKit
class PickerKeyboard: UIControl {
var data: [String] = ["Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sut.", "Sun."]
fileprivate var textStore: String = ""
override func draw(_ rect: CGRect) {
UIColor.black.set()
UIRectFrame(rect)
@kazuhiro4949
kazuhiro4949 / MyViewController.swift
Last active February 11, 2020 03:08
UICollectionViewController including type erased delegate
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
class MyViewController<Delegate: MyViewControllerDelegate>: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var delegate: AnyMyViewControllerDelegate<Delegate>?
var items = [Array<Delegate.Item>]() {