Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
KentarouKanno / Flip a Button
Last active October 4, 2015 03:18 — forked from huytoan/Flip a Button
flip a uibutton
BOOL isFrontViewShowing;
- (void) viewDidLoad{
[super viewDidLoad];
isFrontViewShowing = YES;
UIButton *flipBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
flipBtn.frame = CGRectMake(100, 100, 100, 40);
// UIViewをUIImageに変換する(objective-c)
- (UIImage*)convertUIimageFromUIview:(UIView*)view {
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

現在時刻のミリ秒表示(Swift4)

func nowTime() -> String { /* 2018-04-30 19:33:32.265253+0900 */
    let format = DateFormatter()
    format.dateFormat = "yyyy/MM/dd HH:mm:ss.SSS"
    return format.string(from: Date())
}
var a: AnyObject? = 1
var c = (a as! NSNumber)
var array = ["a","b","c"]
var b = array[c.integerValue]
//=> b = "b"
var d = array[(a as! NSNumber).integerValue + 1]
//=> d = "c"
#import "ViewController.h"
#import <CoreBluetooth/CoreBluetooth.h>
@interface ViewController ()<CBCentralManagerDelegate>
@end
@interface ViewController () {
@property (nonatomic) CBCentralManager *bluetoothManager;
@end
let limitByte: Int = 1000000
var compressionQuality: CGFloat = 1.0
var data: NSData!
repeat {
data = UIImageJPEGRepresentation(images,compressionQuality)
print("Quality\((compressionQuality)) = \(data!.length)")
compressionQuality -= 0.1
} while data?.length > limitByte
// ViewController
var focusCellIndex: NSIndexPath!
func keyboardDidShow(notification: NSNotification) {
let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
UIView.animateWithDuration(0, animations: {
self.mainTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.viewHeight - rect.height)
}) { (boolValue) -> Void in

@IBDesignable & @IBInspectable

★ UIView

import UIKit

@IBDesignable class DesignableView: UIView {
    
@KentarouKanno
KentarouKanno / Array.swift
Last active October 31, 2015 12:54
join separate components
// 配列を区切り文字で連結
(Obj-C)
NSArray *array = @[@"1",@"2",@"3",@"4",@"5"];
NSString *joinedString = [array componentsJoinedByString:@","];
(Swift)
let joinedString = ["1", "2", "3", "4", "5"].joinWithSeparator(",")
//=> "1,2,3,4,5"
@KentarouKanno
KentarouKanno / Pop or Dismiss.swift
Last active September 23, 2021 13:22
UINavigationController Pop or UIViewController dismiss
// Check UINavigationController Pop or UIViewController dismiss
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
let vcs = self.navigationController?.viewControllers
if ((vcs?.contains(self)) == nil) {
print("UINavigationController Pop")
} else {