Skip to content

Instantly share code, notes, and snippets.

View yonat's full-sized avatar

Yonat Sharon yonat

View GitHub Profile
@yonat
yonat / Badge.swift
Last active December 22, 2022 09:40
Rounded UILabel and UIButton, Badged UIBarButtonItem
//
// Badge.swift
// Extensions for Rounded UILabel and UIButton, Badged UIBarButtonItem.
//
// Usage:
// let label = UILabel(badgeText: "Rounded Label");
// let button = UIButton(type: .System); button.rounded = true
// let barButton = UIBarButtonItem(badge: "42", title: "How Many Roads", target: self, action: "answer")
//
// Created by Yonat Sharon on 06.04.2015.
@yonat
yonat / ResizableAsyncImage.swift
Created February 21, 2023 05:59
SwiftUI AsyncImage that fits its image into a frame
import SwiftUI
/// AsyncImage that fits its image into a frame, shows spinner while loading, and an error if it occurs
struct ResizableAsyncImage: View {
let url: URL?
let imageContentMode: ContentMode
let maxWidth: CGFloat?
let maxHeight: CGFloat?
var body: some View {
@yonat
yonat / generate_push_certificate.sh
Created July 11, 2023 08:25
Generate push certificate using fast lane, and create additional p12 for use in the Keychain Access app
# Generate push certificates.
# Usage: generate_push_certificate <app-bundle-id> <user-email> <cert-password>
generate_push_certificate() {
app=$1
user=$2
password=$3
fastlane pem -a "$app" -u "$user" -p "$password"
convert_push_certificate_to_keychain_format "production_${app}_ios.p12" "$password"
}
@yonat
yonat / send_push.sh
Last active July 15, 2023 02:54
Send Apple push notification from terminal
#!/bin/sh
show_help() {
echo ""
echo " $(basename "$0") - Send push notification to an iOS device."
echo ""
echo " Usage:"
echo " $(basename "$0") [options] <app-bundle-id> <cert-file.p12> <cert-password> <push-token>"
echo ""
echo " Options:"
@yonat
yonat / CheckboxButton.swift
Last active March 1, 2024 07:02
Simplest iOS Checkbox (UIKit)
import UIKit
/// Checkbox with title. When checked, `isSelected` is `true`.
class CheckboxButton: UIButton {
/// Handler called when the checkbox is checked or unchecked
var onCheck: ((Bool) -> Void)?
/// - Parameters:
/// - title: Text shown next to the checkbox
/// - color: Color for both checkbox and title