Skip to content

Instantly share code, notes, and snippets.

@HonmaMasaru
HonmaMasaru / ビューの展開 (縦).swift
Created February 17, 2024 01:31
ボタンを縦に展開。Swift Playground用。
import SwiftUI
import PlaygroundSupport
/// ボタン
struct RoundButton: View {
/// サイズ
static let size: CGSize = .init(width: 32, height: 44)
/// 画像
let image: Image
@HonmaMasaru
HonmaMasaru / ビューの展開(円).swift
Created February 17, 2024 01:28
ボタンを円形に展開する。Swift Playground用。
import SwiftUI
import PlaygroundSupport
/// ボタン
struct RoundButton: View {
/// サイズ
static let size: CGSize = .init(width: 32, height: 32)
/// 画像
let image: Image
@HonmaMasaru
HonmaMasaru / postToBluesky.swift
Last active May 8, 2023 20:41
Blueskyに投稿する
import Foundation
import PlaygroundSupport
/// ID
/// - Note: DIDかハンドル
let identifier = "(ID)"
/// パスワード
/// - Note: https://staging.bsky.app/settings/app-passwords で取得する
let appPassword = "(パスワード)"
import SwiftUI
import CoreMotion
import PlaygroundSupport
struct ContentView: View {
/// モーションマネージャー
private let motionManager: CMMotionManager = .init()
/// 角度
@State var angle: Angle = .init()
@HonmaMasaru
HonmaMasaru / CoreMotion.swift
Created April 23, 2023 07:34
PlaygroundでのCoreMotionの利用 (iPadのPlaygroundのみ)
import SwiftUI
import CoreMotion
import PlaygroundSupport
struct ContentView: View {
/// モーションマネージャー
private let motionManager: CMMotionManager = .init()
/// 加速度データ
@State var acceleration: CMAcceleration = .init()
@HonmaMasaru
HonmaMasaru / SwitchShape.swift
Last active March 26, 2023 22:08
Shapeのアニメーション
import SwiftUI
import Combine
import PlaygroundSupport
/// アニメーション対応のシェイプ
struct AnimatableShape: Shape {
/// ポイントデータ
var points: AnimatableCGPointVector
/// アニメーション対象
@HonmaMasaru
HonmaMasaru / MiniPlayerView.swift
Last active February 27, 2023 06:10
YoutubeのミニプレイヤーのようなView
import UIKit
import PlaygroundSupport
final class MyViewController: UIViewController {
override func loadView() {
let view = UIView(frame: .init(x: 0, y: 0, width: 375, height: 667))
view.backgroundColor = .lightGray
self.view = view
}
//
// SeekBar.swift
//
// Created by Honma Masaru on 2023/02/12.
//
import SwiftUI
/// シークバー
struct SeekBar<Bound>: View where Bound: BinaryFloatingPoint, Bound.Stride: BinaryFloatingPoint {
@HonmaMasaru
HonmaMasaru / ColorConverter.swift
Last active November 5, 2022 09:59
ColorConverter.swift
import SwiftUI
import RegexBuilder
import PlaygroundSupport
enum ColorCode {
/// 6文字および8文字のカラーコードの正規表現
/// /^#?([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})?$/
private static let hexCapture = Capture { Repeat(count: 2) { .hexDigit } }
private static let pattern8 = Regex {
Optionally { "#" }
import Foundation
// XORShiftのRandomNumberGenerator
// 参考: https://ja.wikipedia.org/wiki/Xorshift
struct XORShift: RandomNumberGenerator {
private var y: UInt64
init(seed: UInt64 = 2463534242) {
y = seed > 0 ? seed : 2463534242