@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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 以前写tabbar都是在AppDelegate.m里面写,这次看到别人将UITabBarController自定义...
- 我们需要了解下面几个名词 ***UITabBarController ***: 标签试图控制器,可以装多个视图控制...
- 思路 1.我们需要分析一下都要做什么事情:首先,我们需要自定义自己的按钮并替换原生,这样我们就可以在按钮上想怎么玩...
- 需求 类似咸鱼那样中间凸起或者中间自定义图像的tabbar层出不穷,我就想到在tabbar上加小红点这个功能.简单...