-->

2014年10月13日月曜日

UINavigationBarのtitle、backButtonのフォントを変える

まず、「AppDelegate.m」の『- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions』に、
 
    UIFont *barButtonTitleFont = [UIFont fontWithName:@"mplus-2p-light" size:13];
    UIColor *barButtonTitleColor = [UIColor whiteColor];
    [[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeFont:barButtonTitleFont, UITextAttributeTextColor:barButtonTitleColor} forState:UIControlStateNormal];
を記述。これで、BackButtonのフォントが変わる

次に、NavigationControllerの『ViewDidLoad』に、
    UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont fontWithName:@"mplus-2p-light" size:22.0f];
    label.textColor = [UIColor flatWhiteColor];
    label.text = @"タイトル";
    label.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = label;
を記述。これで、タイトルのフォントが変わる。

それはそうと、m+フォントってとても美しいよね

アプリ起動時に指定した画像を表示させる

アプリを起動した時に指定した画像を表示させる
(Twitterの公式クライアントアプリとかであるやつ)
  1. プロジェクト中にある「images.xcassets」を開いて、起動時に表示したい画像をドラッグアンドドロップで設定する。

    ちなみに、必要な画像サイズはinspectorに書いてある。


  2. 「info.plist」に「Status bar is initially hidden」 という項目を追加して、Boolean型のYESに設定する。


  3. 同じく、「View controller-based status bar appearance」という項目を追加して、Boolean型のNOに設定する。
     これで、起動時からステータスバーが表示されなくなる。


  4.  「AppDelegate.m」の-『 (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions』に、
    [NSThread sleepForTimeInterval:1.0];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    を記述する。


    これで、起動から1秒間、設定した画像が表示される
    あとは、フェードアウトするアニメーションを追加したい・・・

2014年10月11日土曜日

インスタンスメソッドの定義方法

今更ながらObj-Cの文法まとめ
あってるかなあ?

きっちりしたインスタンス変数の定義
sampleClass.h
@interface sampleClass:NSObject
{
   NSString *_string; //インスタンス変数の定義
   double _number; //インスタンス変数の定義
}
@property (nonatomic) NSString* string; //プロパティを記述すると、getterとsetterが自動で生成される
@end
sampleClass.m
@implementation sampleClass

@synthesize string = _string; //インスタンス変数とプロパティを明示的に紐付ける

//プロパティを記述していない場合、自分でgetterとsetterを作る
- (double)number{
   return _number;
}
- (void)setNumber:(double)number{
   _number = number;
}
@end
setter/getterを自分で作る場合の利点は、setter/getter内に好きなことを記述できる
例えば、_stringをセットしたついでに、UILabel.textに_stringをセットしたり

・self.propertyの使いどころ
getter/setter/init/deallocのみ_propertyを使い、
その他はself.propertyを使う

2014年10月6日月曜日

JASidePanelControllerでサイドパネルを開くたびに呼ばれるメソッド

JASidePanelControllerを使ってみて、サイドパネルを開くたびにビューを更新しようと思ったけど、デフォルトでその機能がないみたいなのでメモ

JASidePanelController.hに
- (void)prepareShowRightPanel;
を追記

JASidePanelController.mで
- (void)_showRightPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
    self.state = JASidePanelRightVisible;
    [self _loadRightPanel];
    
    [self _adjustCenterFrame];
    
    if (animated) {
        [self _animateCenterPanel:shouldBounce completion:nil];
    } else {
        self.centerPanelContainer.frame = _centerPanelRestingFrame; 
        [self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
        if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
            [self _layoutSideContainers:NO duration:0.0f];
        }
    }
    
    if (self.style == JASidePanelSingleActive) {
        self.tapView = [[UIView alloc] init];
    }
    [self prepareShowRightPanel];//これを追加
    [self _toggleScrollsToTopForCenter:NO left:NO right:YES];
}
次に、JASidePanelControllerのサブクラスに
- (void)prepareShowRightPanel {
    NSLog(@"show right panel");
}
を記述

これで、右のサイドパネルを開くたびに
show right panel
とログが表示される