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 / 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 / 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 / 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: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が複数行になりません。