Skip to content

Instantly share code, notes, and snippets.

@setoh2000
setoh2000 / gist:c8b62654c6e9dccc9c43
Last active August 29, 2015 14:19
Autolayoutでキーボードの高さによってViewを調整する方法(Objective-C版)
// ↓ここで紹介されていたSwiftのコードをObjective-Cに置き換えたものです。
//
// Autolayoutでキーボードの高さによってViewを調整する方法
// http://blog.tsumikiinc.com/article/20150123_autolayout-view.html
//
// StoryboardでUITextViewのBottomのVertical Space ConstraintとbottomLayoutConstraintを接続する必要があります。
// 詳細は元のBlog記事を参照ください。
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *bottomLayoutConstraint;
@setoh2000
setoh2000 / gist:7535335
Created November 18, 2013 21:10
iOS7でステータスバーの文字色を白にしてもカメラロールとかにアクセスすると黒に戻ってしまうのを防ぐ方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
@setoh2000
setoh2000 / MSOrderdDictionary.h
Created April 10, 2013 18:03
順序を保存するNSMutableDictionary NSMutableDictionaryなどを継承するのが結構大変なのでNSMutableDictionaryとキーを保持するNSMutableArrayを内包したものを自作。 自分が使うメンバーしか実装していない。
#import <Foundation/Foundation.h>
@interface MSOrderdDictionary : NSObject <NSCoding>
{
NSMutableDictionary *dictionary;
NSMutableArray *array;
}
+ (id)dictionary;
@setoh2000
setoh2000 / UIView+visible.h
Created November 15, 2012 20:43
UIViewのhiddenの代わりにvisibleを使いたい人へ
#import <UIKit/UIKit.h>
@interface UIView (visible)
- (void)setVisible:(BOOL)flag;
- (BOOL)visible;
@end
@setoh2000
setoh2000 / gist:4027038
Created November 6, 2012 19:48
Viewの周りに余白(margin)を付けて枠線を付ける
CGFloat margin = 3.0;
CGFloat w = aView.bounds.size.width;
CGFloat h = aView.bounds.size.height;
CALayer *borderLayer = [CALayer layer];
borderLayer.borderColor = [UIColor lightGrayColor].CGColor;
borderLayer.borderWidth = 1;
borderLayer.frame = CGRectMake(-margin, -margin, w + margin * 2, h + margin * 2);
[aView.layer addSublayer:borderLayer];
@setoh2000
setoh2000 / gist:3895173
Created October 15, 2012 20:25
Twitter.frameworkやSocial.frameworkのツイート画面でカーソルの初期位置を先頭にする
#import <Twitter/Twitter.h>
#import <Social/Social.h>
// TWTweetComposeViewControllerの場合 (for iOS5)
- (IBAction)tweet:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
// ツイート用の画面をを表示する
TWTweetComposeViewController* composeViewController = [[TWTweetComposeViewController alloc] init];
[composeViewController setInitialText:@"Hello World!"];
@setoh2000
setoh2000 / gist:3264647
Created August 5, 2012 13:01
Mac版のEvernoteクライアントでSmartEverタグの付いたノートを作成するAppleScript
-- 2行目でタイトル、本文、ノートブックを指定してください
tell application "Evernote"
set note1 to create note title "Hello World!" with text "" notebook "TestNotebook"
set tag1 to tag "SmartEver"
assign tag1 to note1
open note window with note1
end tell
@setoh2000
setoh2000 / gist:2979659
Created June 23, 2012 19:36
USB経由でソースコピーしたらファイルの属性が変わってたのでこれで修正 (Mac)
# カレントディレクトリ以下のファイルは644, ディレクトリは755に統一
# (パーミッションを削る方向で)
find . -type f -print0 | xargs -0 chmod go-wx
find . -type f -print0 | xargs -0 chmod u-x
find . -type d -print0 | xargs -0 chmod go-w
@setoh2000
setoh2000 / gist:2884115
Created June 6, 2012 19:30
BlocksKitのselectとmatchの置き換え
//-------------------------------------------------------------------------
// MSBlocks.h
//-------------------------------------------------------------------------
@interface MSBlocks : NSObject
+ (NSArray *)array:(NSArray *)array select:(BOOL(^)(id))block;
+ (id)find:(NSArray *)array match:(BOOL(^)(id))block;
@end
//-------------------------------------------------------------------------
// MSBlocks.m
@setoh2000
setoh2000 / gist:2637433
Created May 8, 2012 17:10
現在表示しているviewControllerを別のviewControllerに差し替える
// 現在のviewControllerを閉じてanotherViewControllerに差し替える
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[viewControllers removeLastObject];
[viewControllers addObject:anotherViewController];
[self.navigationController setViewControllers:viewControllers animated:YES];