某SNS風のスライドするナビゲーションを実装する事になり、AMSlideOutNavigationControllerを使用してみた。
まず、CocoaPodsを利用してプロジェクト内にAMSlideOutNavigationControllerを導入。
CocoaPodsの詳しい利用方法は、これを参考に。
CocoaPodsで導入完了後、
AMSlideOutNavigationController.hをimportする。
import "AMSlideOutNavigationController.h"
次に生成部分
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UIViewController *viewController = [[UIViewController alloc] init]; AMSlideOutNavigationController *slideNavigation = [AMSlideOutNavigationController slideOutNavigation]; [slideNavigation addSectionWithTitle:@""]; [slideNavigation addViewControllerToLastSection:viewController tagged:1 withTitle:@"SampleTitle" andIcon:@""]; [self.window setRootViewController:slideNavigation]; [self.window makeKeyAndVisible];
return YES; }
これでナビゲーションが出来る。
オプションは
[slideNavigation setSlideoutOptions:@{ key: value }]
で簡単に設定出来る。
自分が設定したのは、こんな感じ
[slideNavigation setSlideoutOptions:@{ AMOptionsHeaderHeight: @(0), AMOptionsCellBackground: [UIColor colorWithRed:0.980f green:0.980f blue:0.980f alpha:1.0f], AMOptionsSelectionBackground: [UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1.0f], AMOptionsBackground: [UIColor colorWithRed:0.980f green:0.980f blue:0.980f alpha:1.0f], AMOptionsCellSeparatorUpper: [UIColor colorWithRed:0.949f green:0.949f blue:0.949f alpha:1.0f], AMOptionsCellSeparatorLower: [UIColor colorWithRed:0.949f green:0.949f blue:0.949f alpha:1.0f], AMOptionsCellFontColor: [UIColor blackColor], AMOptionsCellSelectionFontColor: [UIColor blackColor], AMOptionsCellShadowColor: [UIColor clearColor] }];
ヘッダーを消去して、後は背景色を変えたり、文字色を変えたり。
他にも色々あるので、試してみようと思います。
簡単に導入出来て中々良いライブラリかと。
サンプルコードはgitに。