Skip to content

Instantly share code, notes, and snippets.

Avatar

akisute (Masashi Ono) akisute

View GitHub Profile
@akisute
akisute / Playground.swift
Created Jan 12, 2017
Example layout code in playground
View Playground.swift
//: 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 Aug 17, 2016
Font Tester Playground. You can learn how text is drawn and affected by various settings.
View FontTesterPlayground.swift
//: 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
UIFont.leading is broken in iOS 8. Here's how you workaround it.
View HowLeadingIsBroken.log
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 Jun 2, 2016
A practice to improve performance of UITableView by "NOT" reusing cells as far as possible
View AKIdentifierPool.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
UITableViewやUICollectionPoolなどで使用するIdentifierをプールしてユニークに採番するためのユーティリティです。
具体的には以下の様な挙動を示します。
@li identifier発番回数がnumberOfUniqueIdentifiers未満の時、uniqueKeyに対して常にユニークなidentifierを発番します。
@akisute
akisute / project.pbxproj
Created Dec 17, 2015
Settings that are added when pure obj-c project adds a new swift file
View project.pbxproj
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";
View UILabel+Extension.m
- (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 Jul 15, 2015
Small extension to use try-catch error handling in SwiftyJSON
View SwiftyJSON+try.swift
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 Nov 16, 2018
Handling Size Class, UITraitEnvironment, UIContentContainer on iOS 9 (beta 1)
View iPad Air 2
////////////////
// 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 Aug 29, 2015
ParaMangar Example
View example.swift
// 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!
View MainActivity.java
public class MainActivity extends Activity {
@InjectView(R.id.container)
View mContainerView;
@InjectView(R.id.text)
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
You can’t perform that action at this time.