Skip to content

Instantly share code, notes, and snippets.

View yosshi4486's full-sized avatar

yosshi4486 yosshi4486

View GitHub Profile
@yosshi4486
yosshi4486 / ViewController.swift
Created October 13, 2021 05:36
Learn behaviors of lineFragmentRect and lineFragmentUsedRect
//
// ViewController.swift
// UITextViewPractices
//
// Created by yosshi4486 on 2021/10/13.
//
import UIKit
class ViewController: UIViewController {
@yosshi4486
yosshi4486 / TwoColumnTextViewController.swift
Created October 4, 2021 04:23
Two Column TextView with TextKit Sample
class ViewController: UIViewController {
var leftTextView: UITextView!
var rightTextView: UITextView!
lazy var textStorage = NSTextStorage(string: """
「ではみなさんは、そういうふうに川だと云いわれたり、乳の流れたあとだと云われたりしていたこのぼんやりと白いものがほんとうは何かご承知ですか。」先生は、黒板に吊つるした大きな黒い星座の図の、上から下へ白くけぶった銀河帯のようなところを指さしながら、みんなに問といをかけました。
 カムパネルラが手をあげました。それから四五人手をあげました。ジョバンニも手をあげようとして、急いでそのままやめました。たしかにあれがみんな星だと、いつか雑誌で読んだのでしたが、このごろはジョバンニはまるで毎日教室でもねむく、本を読むひまも読む本もないので、なんだかどんなこともよくわからないという気持ちがするのでした。
 ところが先生は早くもそれを見附みつけたのでした。
「ジョバンニさん。あなたはわかっているのでしょう。」
@yosshi4486
yosshi4486 / SubtitledNavigationTitleView.swift
Created August 30, 2021 01:08
Subtitled navigation title view
class SubtitledNavigationTitleView: UIView {
let titleLabel: UILabel = {
let label = UILabel()
label.adjustsFontForContentSizeCategory = true
label.font = .preferredFont(forTextStyle: .headline)
label.textAlignment = .center
label.numberOfLines = 1
return label
}()
@yosshi4486
yosshi4486 / StringToImageConvert.swift
Created August 12, 2021 06:50
Convert a string to UIImage by using UIGraphicsImageRenderer.
let string = "🤩"
let bounds = CGRect(x: 0, y: 0, width: 30, height: 30)
let image = UIGraphicsImageRenderer(size: bounds.size).image { context in
let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.preferredFont(forTextStyle: .body),
.foregroundColor: UIColor.label
]
@yosshi4486
yosshi4486 / ReviewRequestManager.swift
Last active August 26, 2021 19:34
Implementation example of Review Request in iOS.
//
// ReviewRequestManager.swift
//
// Created by yosshi4486 on 2021/07/22.
//
import StoreKit
/// The global variable to get current app version.
///
@yosshi4486
yosshi4486 / NavigationController+BarAppearance.swift
Last active May 22, 2021 02:29
viewWillAppearでこういうappearance設定を呼んであげると切り替えがうまくいく
extension UINavigationController {
/*
iOS13以降では、利用可能な場合はAppearance系API経由で見た目を設定するようにする。
 視覚情報と情報構造の切り分けを意識する。
*/
/// 不透明のNavigationBarを構成する
func configureOpaqueBar() {
let navBarAppearance = UINavigationBarAppearance()
@yosshi4486
yosshi4486 / ImageCodeOfCanMove.swift
Created May 2, 2021 03:57
ImageCode of CanMove.
extension Array where Element == List {
    func canMove(into otherContainer: List) -> Bool {
        return allSatisfy({ $0.canMove(into: otherContainer) })
    }
}
@yosshi4486
yosshi4486 / FirstRelease.swift
Created April 23, 2021 23:16
ファーストリリースに関しての自分の脳内モデル
struct Feature {
var title: String
}
extension Feature: CustomStringConvertible {
var description: String {
return title
}
@yosshi4486
yosshi4486 / AccessibleDate.swift
Created April 14, 2021 05:32
日付表示のアクセシビリティ
private func accessibilityLabelForCreatedDateLabel(from date: Date) -> String {
return String(format: NSLocalizedString("Created: %@", comment: "An accessibility label of created date."), self.accessibilityLabel(for: date) ?? "")
}
private func accessibilityLabelForUpdatedDateLabel(from date: Date) -> String {
return String(format: NSLocalizedString("Updated: %@", comment: "An accessibility label of updated date."), self.accessibilityLabel(for: date) ?? "")
}
private func accessibilityLabel(for date: Date) -> String? {
let timeComponentFormatter = DateComponentsFormatter()
@yosshi4486
yosshi4486 / Accessibility.swift
Created April 13, 2021 11:24
カスタムView(タスクチェックボタン)のアクセシビリティ対応
// 画像のサイズよりもタップ領域を広げたいので、contentViewを別途設けており、それのアクセシビリティ要素にしたい
taskContentView.isAccessibilityElement = true
taskContentView.accessibilityLabel = NSLocalizedString("Task Status", comment: "")
taskContentView.accessibilityCustomActions = [
    UIAccessibilityCustomAction(name: NSLocalizedString("Toggle task status", comment: ""), actionHandler: { [weak self] (action) -> Bool in
self?.toggleDone(action)
return true
    })
]