mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
34 lines
1006 B
Markdown
34 lines
1006 B
Markdown
### Creating a tab bar
|
|
|
|
<!--<div class="material-code-render" markdown="1">-->
|
|
#### Swift
|
|
|
|
```swift
|
|
let tabBar = MDCTabBar(frame: view.bounds)
|
|
tabBar.items = [
|
|
UITabBarItem(title: "Recents", image: UIImage(named: "phone"), tag: 0),
|
|
UITabBarItem(title: "Favorites", image: UIImage(named: "heart"), tag: 0),
|
|
]
|
|
tabBar.itemAppearance = .titledImages
|
|
tabBar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
|
|
tabBar.sizeToFit()
|
|
view.addSubview(tabBar)
|
|
```
|
|
|
|
#### Objective-C
|
|
|
|
```objc
|
|
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.autoresizingMask =
|
|
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
|
|
[tabBar sizeToFit];
|
|
[self.view addSubview:tabBar];
|
|
```
|
|
|
|
<!--</div>-->
|