This file contains 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
{ | |
"title": "カスタム", | |
"rules": [ | |
{ | |
"description": "control + return to esc", | |
"manipulators": [ | |
{ | |
"from": { | |
"key_code": "return_or_enter", | |
"modifiers": { |
This file contains 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
var minimumLineHeight: CGFloat = 0 | |
var maximumLineHeight: CGFloat = 0 | |
let paragraphSettings: [CTParagraphStyleSetting] = [ | |
CTParagraphStyleSetting(spec: .minimumLineHeight, valueSize: MemoryLayout<CGFloat>.size, value: &minimumLineHeight), | |
CTParagraphStyleSetting(spec: .maximumLineHeight, valueSize: MemoryLayout<CGFloat>.size, value: &maximumLineHeight) | |
] | |
// sizeof(T) ... MemoryLayout<T>.size | |
let paragraphStyle = CTParagraphStyleCreate(paragraphSettings, paragraphSettings.count) |
This file contains 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 Cocoa | |
extension NSView { | |
@IBInspectable var backgroundColor: NSColor? { | |
get { | |
guard let layer = layer, let backgroundColor = layer.backgroundColor else {return nil} | |
return NSColor(cgColor: backgroundColor) | |
} | |
set { |
This file contains 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 UIKit | |
extension UIView { | |
func resetScrollsToTop(_ targetScrollView: UIScrollView) { | |
if self is UIScrollView { | |
(self as! UIScrollView).scrollsToTop = self == targetScrollView | |
} | |
for v in subviews { | |
v.resetScrollsToTop(targetScrollView) |
This file contains 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 UIKit | |
extension UIImage { | |
func paintedImage(color: UIColor) -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(size, false, 0.0) | |
let bounds = CGRectMake(0, 0, size.width, size.height) | |
let context = UIGraphicsGetCurrentContext() |
This file contains 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
class MyView: NSView { | |
override func draw(_ dirtyRect: NSRect) { | |
super.draw(dirtyRect) | |
guard let ctx = NSGraphicsContext.current?.cgContext else {return} | |
var rects: UnsafePointer<NSRect>? | |
var count = 0 | |
self.getRectsBeingDrawn(&rects, count: &count) |
This file contains 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 Cocoa | |
class MyConstraintLayoutManager: CAConstraintLayoutManager { | |
var isImplicitAnimationsDisabled: Bool = true | |
override func layoutSublayers(of layer: CALayer) { | |
// サブレイヤーのレイアウト時の暗黙アニメーションを無効化 | |
CATransaction.begin() | |
CATransaction.setDisableActions(self.isImplicitAnimationsDisabled) |
This file contains 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
{ | |
"title": "カスタム", | |
"rules": [ | |
{ | |
"description": "左option: 英数/右command: かな", | |
"manipulators": [ | |
{ | |
"type": "basic", | |
"from": { | |
"key_code": "left_option", |
This file contains 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
// https://qiita.com/usagimaru/items/4306f261457e82641e4a | |
UIView.perform(.delete, | |
on: [], | |
options: [.beginFromCurrentState, .allowUserInteraction], | |
animations: { | |
aView.frame = targetFrame | |
}, | |
completion: nil) |
This file contains 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 Cocoa | |
extension NSBezierPath { | |
var cgPath: CGPath { | |
// https://stackoverflow.com/questions/1815568/how-can-i-convert-nsbezierpath-to-cgpath | |
let path = CGMutablePath() | |
var points = [CGPoint](repeating: .zero, count: 3) | |
for i in 0 ..< self.elementCount { |