Skip to content

Instantly share code, notes, and snippets.

View Slowhand0309's full-sized avatar
🏠
Working from home

Slowhand Slowhand0309

🏠
Working from home
View GitHub Profile
@Slowhand0309
Slowhand0309 / ViewController.swift
Created September 12, 2019 02:27
[ダブルタップをUITapGestureRecognizerで設定する] #iOS
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let gesture = UITapGestureRecognizer()
gesture.numberOfTapsRequired = 2 // ここで回数を設定する
gesture.rx.event.asSignal()
.emit(onNext: { [weak self] _ in
// do somthing...
@Slowhand0309
Slowhand0309 / sample.kt
Last active October 10, 2020 16:55
[Callback to Coroutines] use suspendCoroutine. #Kotlin
/*
before
fun asyncLoad(callback: (result: String) -> Unit) {
load { result ->
callback(result)
}
}
*/
suspend fun asyncLoad(): String = suspendCoroutine { continuation ->
@Slowhand0309
Slowhand0309 / ArrayExtensions.swift
Created August 17, 2019 09:26
[Swift extensions] #iOS
public extension Array {
/// Secure access at index.
///
/// let array = [1, 2]
/// array[safe: 0] // Optional(1)
/// array[safe: 1] // Optional(2)
/// array[safe: 2] // nil
subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
@Slowhand0309
Slowhand0309 / UIButton+Rx.swift
Created August 17, 2019 09:03
[UIButton enable style binder] #iOS
import UIKit
import RxSwift
import RxCocoa
extension Reactive where Base: UIButton {
var enabledStyle: Binder<Bool> {
return Binder(self.base) { base, enabled in
base.isEnabled = enabled
base.backgroundColor = enabled ? UIColor.xxx : UIColor.xxx
base.setTitleColor(enabled ? UIColor.xxx : UIColor.xxx, for: .normal)
@Slowhand0309
Slowhand0309 / UIPaddingTextField.swift
Last active October 10, 2020 16:54
[Padding UITextField] Add padding to UITextField #iOS
import UIKit
@IBDesignable class UIPaddingTextField: UITextField {
// MARK: Properties
@IBInspectable var padding: CGPoint = CGPoint(x: 8.0, y: 0.0)
// MARK: Internal Methods
override func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y)
@Slowhand0309
Slowhand0309 / ViewController.swift
Last active August 16, 2019 02:29
[UIImagePickerController sample] #iOS
import UIKit
import Photos
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
private func selectFromLibrary() {
@Slowhand0309
Slowhand0309 / FAB.swift
Created August 1, 2019 08:48
[Floating Action Button for iOS] #iOS
@IBOutlet weak var floatingActionButton: UIView! {
didSet {
floatingActionButton.layer.cornerRadius = floatingActionButton.width / 2.0
floatingActionButton.layer.shadowOpacity = 0.8
floatingActionButton.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
floatingActionButton.layer.shadowColor = UIColor.darkGray.cgColor
}
}
@Slowhand0309
Slowhand0309 / app-build-google-services.gradle
Created July 28, 2019 06:49
[Gradle Tips] #Android #Gradle
// buildTypesに応じたgoogle-services.jsonをapp/.へコピー
gradle.taskGraph.beforeTask { Task task ->
if (task.name ==~ /process.*GoogleServices/) {
applicationVariants.all { variant ->
if (task.name ==~ /(?i)process${variant.name}GoogleServices/) {
copy {
from "src/${variant.name}"
into "."
include "google-services.json"
}
@Slowhand0309
Slowhand0309 / ViewController.swift
Last active July 27, 2019 05:37
[Keyboard Event With RxSwift] #iOS
import RxSwift
import RxCocoa
class ViewController: UIViewController {
@IBOutlet private weak var bottomConstraint: NSLayoutConstraint!
private let disposeBag = DisposeBag()
override func viewDidLoad() {
@Slowhand0309
Slowhand0309 / ActivityExt.kt
Last active September 18, 2020 07:49
[Kotlin Extension Activity] #Kotlin #Android
/**
* カスタムActivityの取得
* 取得できない場合はnull
*/
val Activity.rootApplication: RootApplication?
get() = (application as? RootApplication)
/**
* 現在フォーカスされているViewを元にKeyboardを非表示にする
*/