Skip to content

Instantly share code, notes, and snippets.

Satori Maru usagimaru

Block or report user

Report or block usagimaru

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@usagimaru
usagimaru / NSBezierPath+SmoothRoundedRect.swift
Last active Nov 14, 2018
A Swift extension of NSBezierPath for drawing the smooth rounded rectangles like iOS 7 icons.
View NSBezierPath+SmoothRoundedRect.swift
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 {
@usagimaru
usagimaru / system_animation.swift
Last active Aug 9, 2018
Tips of a motion like iOS system transition.
View system_animation.swift
// https://qiita.com/usagimaru/items/4306f261457e82641e4a
UIView.perform(.delete,
on: [],
options: [.beginFromCurrentState, .allowUserInteraction],
animations: {
aView.frame = targetFrame
},
completion: nil)
@usagimaru
usagimaru / NSViewController.swift
Created May 17, 2018
NSViewController StoryboardInstantiatable
View NSViewController.swift
import Cocoa
protocol StoryboardInstantiatable: class {
/*
継承クラスで以下を定義してください
typealias StoryboardInstantiatableViewController = <#YourViewController#>
static var storyboardName: String {
return "<#Storyboard Name#>"
}
@usagimaru
usagimaru / MyConstraintLayoutManager.swift
Created Apr 17, 2018
Disable implicit animations of CAConstraintLayoutManager.
View MyConstraintLayoutManager.swift
import Cocoa
class MyConstraintLayoutManager: CAConstraintLayoutManager {
var isImplicitAnimationsDisabled: Bool = true
override func layoutSublayers(of layer: CALayer) {
// サブレイヤーのレイアウト時の暗黙アニメーションを無効化
CATransaction.begin()
CATransaction.setDisableActions(self.isImplicitAnimationsDisabled)
@usagimaru
usagimaru / NSView_optimize_drawRect.swift
Last active Apr 6, 2018
Optimize NSView's drawRect
View NSView_optimize_drawRect.swift
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)
@usagimaru
usagimaru / UIImage+TintColor.swift
Created Mar 10, 2018
Paint UIImage with any UIColor
View UIImage+TintColor.swift
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()
@usagimaru
usagimaru / ScrollsToTopResetter.swift
Last active Mar 10, 2018
Reset `scrollsToTop` flags to all scrollviews
View ScrollsToTopResetter.swift
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)
@usagimaru
usagimaru / NSView+BackgroundColor.swift
Created Mar 10, 2018
IBInspectable backgroundColor for NSView
View NSView+BackgroundColor.swift
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 {
View paragraph_style.swift
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)
@usagimaru
usagimaru / esc.json
Last active Feb 5, 2018
complex_modifications for Karabiner-Elements: [control] [return] to [esc]
View esc.json
{
"title": "カスタム",
"rules": [
{
"description": "control + return to esc",
"manipulators": [
{
"from": {
"key_code": "return_or_enter",
"modifiers": {
You can’t perform that action at this time.