This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
convenience init(red: UInt8, green: UInt8, blue: UInt8) { | |
self.init(red: CGFloat(red) / 255, green: CGFloat(green) / 255, blue: CGFloat(blue) / 255, alpha: 1) | |
} | |
} | |
// cf. http://www.tokyo-colors.com/dictionary/dictionary_category/japanese-color/ | |
let colors: [UIColor] = [ | |
UIColor(red: 251, green: 202, blue: 77), | |
UIColor(red: 163, green: 111, blue: 162), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func circle(p1: CGPoint, _ p2: CGPoint, _ p3: CGPoint) -> (center: CGPoint, radius: CGFloat) { | |
let p = ((p1.y - p3.y) * (p1.y * p1.y - p2.y * p2.y + p1.x * p1.x - p2.x * p2.x) - (p1.y - p2.y) * (p1.y * p1.y - p3.y * p3.y + p1.x * p1.x - p3.x * p3.x)) / (2 * (p1.y - p3.y) * (p1.x - p2.x) - 2 * (p1.y - p2.y) * (p1.x - p3.x)) | |
let q = ((p1.x - p3.x) * (p1.x * p1.x - p2.x * p2.x + p1.y * p1.y - p2.y * p2.y) - (p1.x - p2.x) * (p1.x * p1.x - p3.x * p3.x + p1.y * p1.y - p3.y * p3.y)) / (2 * (p1.x - p3.x) * (p1.y - p2.y) - 2 * (p1.x - p2.x) * (p1.y - p3.y)) | |
let center = CGPoint(x: p, y: q) | |
let radius = hypot(p1.x - center.x, p1.y - center.y) | |
return (center: center, radius: radius) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am mishimay on github. | |
* I am mishimay (https://keybase.io/mishimay) on keybase. | |
* I have a public key whose fingerprint is 0810 59F4 0A02 723C 3B58 485A B889 2170 FAB5 AE6F | |
To claim this, I am signing this object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: swift remove_alpha_channel.swift filename.png | |
import Foundation | |
import CoreImage | |
let arguments = CommandLine.arguments | |
let filename = arguments[1] | |
let dataProvider = CGDataProvider(filename: filename)! | |
let cgImage = CGImage(pngDataProviderSource: dataProvider, decode: nil, shouldInterpolate: true, intent: .defaultIntent)! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MyScrollView: UIViewRepresentable { | |
let swiftUIView: AnyView | |
func makeUIView(context: UIViewRepresentableContext<ContentView.MyScrollView>) -> UIView { | |
let hosting = UIHostingController(rootView: swiftUIView) | |
let width = UIScreen.main.bounds.width | |
let size = hosting.view.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)) | |
hosting.view.frame = CGRect(x: 0, y: 0, width: width, height: size.height) | |
let view = UIScrollView() | |
view.alwaysBounceVertical = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PagingScrollView<Content: View>: UIViewRepresentable { | |
let size: CGSize | |
@Binding var contentOffset: CGPoint | |
@ViewBuilder let content: () -> Content | |
class Coordinator: NSObject, UIScrollViewDelegate { | |
var hostingController: UIHostingController<Content>? | |
var contentOffsetChanged: ((CGPoint) -> Void)? | |
func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
contentOffsetChanged?(scrollView.contentOffset) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let appearance = UITabBarAppearance() | |
appearance.configureWithTransparentBackground() | |
appearance.backgroundColor = backgroundColor | |
appearance.backgroundImage = backgroundImage | |
[appearance.stackedLayoutAppearance, | |
appearance.compactInlineLayoutAppearance, | |
appearance.inlineLayoutAppearance] | |
.forEach { | |
$0.selected.iconColor = selectedColor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
ScrollView { | |
LazyVGrid(columns: [.init(.flexible()), .init(.flexible())]) { | |
ForEach((0...79), id: \.self) { | |
let codepoint = $0 + 0x1f600 | |
let emoji = String(Character(UnicodeScalar(codepoint)!)) | |
Text("\(emoji)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContainerView<Content: View>: View { | |
@ViewBuilder let content: Content | |
var body: some View { | |
content | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
protocol AppearanceProtocol { | |
var text: String { get } | |
} | |
struct MyView<Appearance: AppearanceProtocol>: View { | |
let appearance: Appearance | |
var body: some View { |
OlderNewer