@interface AppDelegate ()
@property (nonatomic, retain)UITabBarController *tabBarController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *firstNaVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstNaVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:1000];
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNaVC = [[UINavigationController alloc] initWithRootViewController:secondVC];
secondNaVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1001];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[firstNaVC, secondNaVC];
[self.window addSubview:self.tabBarController.view];
self.window.rootViewController = self.tabBarController;
[self addCenterTabbarButton];
[self.window makeKeyAndVisible];
return YES;
}
- (void)addCenterTabbarButton {
UIButton *centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
// [centerButton setImage:[UIImage imageNamed:@"camera.png"] forState:0];
UIImage *centerImage = [UIImage imageNamed:@"camera.png"];
centerButton.frame = CGRectMake(0, 0, centerImage.size.width, centerImage.size.height);
[centerButton setImage:centerImage forState:0];
[centerButton addTarget:self action:@selector(centerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
CGFloat imageHeight = centerImage.size.height;
CGFloat barHeight = self.tabBarController.tabBar.frame.size.height;
CGFloat delta = imageHeight - barHeight;
if (delta <= 0) {
centerButton.center = self.tabBarController.tabBar.center;
} else {
CGPoint center = self.tabBarController.tabBar.center;
center.y = center.y - delta / 2.0;
centerButton.center = center;
}
[self.tabBarController.view addSubview:centerButton];
}
- (void)centerButtonClick:(UIButton *)button {
NSLog(@"centerButton did clicked");
}
自定義UITabBarController
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 以前寫tabbar都是在AppDelegate.m里面寫,這次看到別人將UITabBarController自定義...
- 我們需要了解下面幾個(gè)名詞 ***UITabBarController ***: 標(biāo)簽試圖控制器,可以裝多個(gè)視圖控制...
- 思路 1.我們需要分析一下都要做什么事情:首先,我們需要自定義自己的按鈕并替換原生,這樣我們就可以在按鈕上想怎么玩...
- 需求 類似咸魚那樣中間凸起或者中間自定義圖像的tabbar層出不窮,我就想到在tabbar上加小紅點(diǎn)這個(gè)功能.簡(jiǎn)單...