Skip to content

Instantly share code, notes, and snippets.

@naotokui
naotokui / gist:4063901
Created November 13, 2012 04:18
UIView RoundedCorner Category
#import <QuartzCore/QuartzCore.h>
@implementation UIView (UIView_RoundCorner)
- (void) setCornersRoundedWithRadius: (float) cornerRadius
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(cornerRadius, cornerRadius)];
@naotokui
naotokui / gist:4122008
Created November 20, 2012 23:32
Background execution with UIBackgroundTaskIdentifier
// バックグラウンド処理のスタートを宣言
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
/* ここでやりたい処理をする */
// バックグラウンド処理の終了
if (bgTask != UIBackgroundTaskInvalid){
@naotokui
naotokui / gist:ee983e0c384fa5acd49f
Created November 9, 2015 06:32
Xcode - Arguments Passed on Launch - Show UIView Alignment Rects
-UIViewShowAlignmentRects YES
@naotokui
naotokui / gist:4316601
Created December 17, 2012 08:15
How to tell the state of iOS application i.e, background, active, inactive.
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ...
// UIApplicationStateActive,
// UIApplicationStateInactive,
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@naotokui
naotokui / gist:4343823
Created December 20, 2012 08:34
Update a specific cell in tableview
- (void)reloadRow: (NSInteger) row inSection:(NSInteger) section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
NSArray *indexPaths = [[NSArray alloc] initWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; //UITableViewRowAnimationFace or whatever
[indexPaths release];
}
@naotokui
naotokui / gist:4523569
Created January 13, 2013 11:12
Reset NSUserDefaults
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
@naotokui
naotokui / gist:4984986
Last active December 13, 2015 22:29
Sending image via Line.app Lineで画像データを送る方法
NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"Flower.jpg"] , 0.5);
UIPasteboard* pasteboard = [UIPasteboard pasteboardWithName: LINE_PASTEBOARD create: YES];
[pasteboard setData: data forPasteboardType: (NSString *)kUTTypeJPEG];
// LINE
NSString *escapedStr = [LINE_PASTEBOARD stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *urlStr = [NSString stringWithFormat:@"line://msg/image/%@", escapedStr];
NSURL *sndUrl = [NSURL URLWithString:urlStr];
if ([[UIApplication sharedApplication] canOpenURL:sndUrl]) {
@naotokui
naotokui / 0_reuse_code.js
Created October 25, 2013 00:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
+ (ClassName *)sharedInstance {
static dispatch_once_t once;
static ClassName *sharedInstance;
dispatch_once(&once, ^ { sharedInstance = [[ClassName alloc] init]]; });
return sharedInstance;
}