Skip to content

Instantly share code, notes, and snippets.

@akisute
akisute / Playground.swift
Created January 12, 2017 10:19
Example layout code in playground
//: Playground - noun: a place where people can play
import Foundation
import UIKit
import PlaygroundSupport
// Needs this settings first before using UIWebView to render web pages in Playground
// Also required to run Auto Layout
PlaygroundPage.current.needsIndefiniteExecution = true
@akisute
akisute / FontTesterPlayground.swift
Created August 17, 2016 07:35
Font Tester Playground. You can learn how text is drawn and affected by various settings.
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
// To continue running NSURLSession async download, make this playground page keep running
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let font = UIFont.systemFontOfSize(16.0)
@akisute
akisute / HowLeadingIsBroken.log
Last active May 2, 2018 05:43
UIFont.leading is broken in iOS 8. Here's how you workaround it.
iOS 8
2016-07-13 22:49:18.634 leading_broken[266:12919] font <UICTFont: 0x14f560af0> font-family: "HiraKakuProN-W6"; font-weight: bold; font-style: normal; font-size: 21.00pt
2016-07-13 22:49:18.635 leading_broken[266:12919] font pointSize 21.000000
2016-07-13 22:49:18.635 leading_broken[266:12919] font lineHeight 21.000000
2016-07-13 22:49:18.635 leading_broken[266:12919] font ascender 18.480000
2016-07-13 22:49:18.635 leading_broken[266:12919] font descender -2.520000
2016-07-13 22:49:18.636 leading_broken[266:12919] font leading 21.000000
2016-07-13 22:49:18.636 leading_broken[266:12919] ctfont pointSize 21.000000
2016-07-13 22:49:18.636 leading_broken[266:12919] ctfont boundingBox {{-9.072000000000001, -10.038}, {37.590000000000003, 37.590000000000003}}
@akisute
akisute / AKIdentifierPool.h
Created June 2, 2016 08:59
A practice to improve performance of UITableView by "NOT" reusing cells as far as possible
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
UITableViewやUICollectionPoolなどで使用するIdentifierをプールしてユニークに採番するためのユーティリティです。
具体的には以下の様な挙動を示します。
@li identifier発番回数がnumberOfUniqueIdentifiers未満の時、uniqueKeyに対して常にユニークなidentifierを発番します。
@akisute
akisute / project.pbxproj
Created December 17, 2015 07:38
Settings that are added when pure obj-c project adds a new swift file
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
SWIFT_OBJC_BRIDGING_HEADER = "myapp/myapp-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@akisute
akisute / UILabel+Extension.m
Created October 6, 2015 08:41
🍎 Hiragino = 💩
- (CGSize)sizeThatFitsHiraginoCompatible:(CGSize)size
{
// ヒラギノフォント(日本語)で正確に描画サイズを取得する
// http://qiita.com/yusuga_/items/2be8c55ca561bba44702
// ヒラギノ (Hiragino Kaku Gothic, Hiragino Mincho) の時だけ補正をかける
CGSize s = [self sizeThatFits:size];
UIFont *font = self.font;
if ([font.familyName hasPrefix:@"Hiragino"]) {
s.width = ceil(s.width);
s.height = ceil(s.height + fabs(font.descender));
@akisute
akisute / SwiftyJSON+try.swift
Created July 15, 2015 09:30
Small extension to use try-catch error handling in SwiftyJSON
import Foundation
public enum JSONError: Int, ErrorType {
case UnsupportedType = 999
case IndexOutOfBounds = 900
case WrongType = 901
case ErrorNotExist = 500
}
public extension JSON {
@akisute
akisute / iPad Air 2
Last active November 16, 2018 02:46
Handling Size Class, UITraitEnvironment, UIContentContainer on iOS 9 (beta 1)
////////////////
// on iPad Air 2
////////////////
// Boot as portrait
2015-06-15 19:57:47.597 ios9[16003:229076] viewDidLoad()
2015-06-15 19:57:47.598 ios9[16003:229076] viewWillAppear - false
2015-06-15 19:57:47.601 ios9[16003:229076] traitCollectionDidChange - nil
2015-06-15 19:57:47.602 ios9[16003:229076] viewWillLayoutSubviews()
2015-06-15 19:57:47.602 ios9[16003:229076] viewDidLayoutSubviews()
@akisute
akisute / example.swift
Last active August 29, 2015 14:17
ParaMangar Example
// Basic example
let duration = 1.0
self.animator = ParaMangar.renderViewForDuration(self.targetView, duration: duration, frameInterval: 2).toFile("Sample1", completion: {path in
self.animator = nil
println("Completed: \(path)")
})
// More complex example
// Render UIView animations!
public class MainActivity extends Activity {
@InjectView(R.id.container)
View mContainerView;
@InjectView(R.id.text)
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {