材料组件选项卡栏底部导航

时间:2017-10-29 13:56:44

标签: ios objective-c material-components

如何创建材质组件标签栏底部导航?文档描述 我必须实现positionForBar:并返回UIBarPositionBottom以将标签栏配置为底部导航栏。条形图将自动更新为适当的样式。它看起来不起作用 - 例如:

ViewController.h ...

@interface ViewController : MDCCollectionViewController <MDCTabBarDelegate>

ViewController.m

- (void)viewDidLoad {
 [super viewDidLoad];
 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
// Do any additional setup after loading the view, typically from a nib.

self.appBar = [[MDCAppBar alloc] init];
[self addChildViewController:self.appBar.headerViewController];
self.appBar.headerViewController.headerView.backgroundColor = [UIColor colorWithRed:120.0/255 green:144.0/255 blue:156.0/255 alpha:1.0];//rgba(38,50,56 ,1)
self.appBar.headerViewController.headerView.trackingScrollView = self.collectionView;
self.appBar.navigationBar.tintColor = [UIColor blackColor];
[self.appBar addSubviewsToParent];

self.title = @"W0rX";

MDCTabBar *tabBar =  [[MDCTabBar alloc] initWithFrame:self.view.bounds];
tabBar.items = @[
                 [[UITabBarItem alloc] initWithTitle:@"Recents" image:[UIImage imageNamed:@"phone"] tag:0],
                 [[UITabBarItem alloc] initWithTitle:@"Favorites" image:[UIImage imageNamed:@"heart"] tag:0],
                 ];
tabBar.itemAppearance = MDCTabBarItemAppearanceTitledImages;
tabBar.delegate = self;

tabBar.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[tabBar sizeToFit];
[self.view addSubview:tabBar];
}

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
NSLog(@"######## UIBarPositionBottom");
return UIBarPositionBottom;
}

1 个答案:

答案 0 :(得分:0)

感谢您使用MDC-iOS。

看起来您的代码几乎就在那里!

缺少的是将标签栏的框架设置在屏幕底部。有关如何执行此操作的示例,请参阅BottomNavigationBarExample。在该示例视图控制器中,标签栏位于viewWillLayoutSubviews

中屏幕的底部
barFrame.origin.y = CGRectGetMaxY(bounds) - barFrame.size.height

我知道你只是在这里放了一段代码但我没有看到你设置原点,除非你实例化标签栏。你的行

MDCTabBar *tabBar =  [[MDCTabBar alloc] initWithFrame:self.view.bounds];

将左上角作为标签栏(0,0)的原点放置。哪个好。但是你最终需要将它移到视图的底部。

BTW:另请查看MDCTabBarViewController,这与UITabBarViewController非常相似。它可能对你有用,取决于你想要做什么。

相关问题