Skip to content

Instantly share code, notes, and snippets.

View TachibanaKaoru's full-sized avatar
🏠
Working from home

Tachibana Kaoru TachibanaKaoru

🏠
Working from home
View GitHub Profile
@TachibanaKaoru
TachibanaKaoru / ViewController.m
Last active December 25, 2015 20:38
UILabelとUITextViewのsizeWithFont:constrainedToSizeを使って表示テキストによってサイズを変更します。 (http://www.toyship.org/archives/1437)
- (void)viewDidLoad
{
[super viewDidLoad];
// UILabelの場合
UILabel* myLabel = [[UILabel alloc] init];
myLabel.text = @"Every great iOS app starts with a great idea, but translating that idea into actions requires some planning. Every iOS app relies heavily on design patterns, and those design patterns influence much of the code you need to write. So before you write any code, take the time to explore the possible techniques and technologies available for writing that code. Doing so can save you a lot of time and frustration.";
myLabel.font = [UIFont systemFontOfSize:12.0];
myLabel.backgroundColor = [UIColor blueColor];
myLabel.numberOfLines = 0; //これがないとUILabelが複数行になりません。
@TachibanaKaoru
TachibanaKaoru / ViewController.m
Last active December 25, 2015 20:38
NSAttributedStringのboundingRectWithSize:options:attributes:context:を使って表示テキストにあわせてサイズを調整します。 (iOS6以上) (http://www.toyship.org/archives/1437)
- (void)viewDidLoad
{
[super viewDidLoad];
//boundingRectWithSize:options:contextを使う
NSDictionary *attributes = @{ NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:12.0f] };
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Every great iOS app starts with a great idea, but translating that idea into actions requires some planning. Every iOS app relies heavily on design patterns, and those design patterns influence much of the code you need to write. So before you write any code, take the time to explore the possible techniques and technologies available for writing that code. Doing so can save you a lot of time and frustration."
attributes:attributes];
@TachibanaKaoru
TachibanaKaoru / ViewController.m
Last active December 25, 2015 20:39
UITextViewのテキスト描画が終わったら微調整してサイズを変更する方法 (http://www.toyship.org/archives/1437)
CGRect newFrame = self.myTextView.frame;
newFrame.size.height = self.myTextView.contentSize.height;
self.myTextView.frame = newFrame;
@TachibanaKaoru
TachibanaKaoru / gist:7278793
Last active December 27, 2015 05:59
catch notification from iPod player.
// (link MediaPlayer.framework)
// get item changed notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePlayerStatus:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:nil];
// get status changed notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePlayerStatus:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:nil];
// get volume changed notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePlayerStatus:) name:MPMusicPlayerControllerVolumeDidChangeNotification object:nil];
@TachibanaKaoru
TachibanaKaoru / gist:7847173
Created December 7, 2013 19:09
Screen Capture Notification
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleScreenCapture:)
name:UIApplicationUserDidTakeScreenshotNotification
object:nil];
ALAssetsGroup *group;
[group setAssetsFilter:onlyPhotosFilter];
NSInteger lastPhotoIndex = [group numberOfAssets];
NSMutableIndexSet* photoIndexes = [[NSMutableIndexSet alloc] init];
[photoIndexes addIndex:lastPhotoIndex-1];
[group enumerateAssetsAtIndexes:photoIndexes options:nil usingBlock:assetsEnumerationBlock];
@TachibanaKaoru
TachibanaKaoru / gist:7847431
Created December 7, 2013 19:32
カメラロールの取得
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
NSUInteger groupTypes = ALAssetsGroupSavedPhotos;
[assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
@TachibanaKaoru
TachibanaKaoru / gist:8068940
Last active January 1, 2016 00:49
韓国語の変数名
// 韓国語
int 사과 = 5;
int 바나나 = 3;
int 총 = 사과 + 바나나;
NSLog(@"총 %d",총);
@TachibanaKaoru
TachibanaKaoru / gist:8068946
Created December 21, 2013 12:50
タイ語の変数名
// タイ語
int แอปเปิล = 5;
int กล้วย = 3;
int รวมทั้งหมด = แอปเปิล + กล้วย;
NSLog(@"รวมทั้งหมด %d",รวมทั้งหมด);
@TachibanaKaoru
TachibanaKaoru / gist:8068947
Created December 21, 2013 12:51
日本語の変数名その2
NSArray* クラス全員 = [[NSArray alloc] init];
for( id 選ばれた人 in クラス全員){
[選ばれた人 description];
}