自定义Tabbar18.9.29发布
导入TabBar.h.m和TabBarItem.h.m类库
TabBar需要一个全局的witch,height
// 屏幕高度
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
// 屏幕宽度
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
下面是具体实现
根据图片内容一步一步实现即可
下面是图片内代码
-
(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];
[self.window makeKeyAndVisible];LLHomeViewController *homeViewController = [[LLHomeViewController alloc] init];
LLSameCityViewController *sameCityViewController = [[LLSameCityViewController alloc] init];
LLMessageViewController *messageViewController = [[LLMessageViewController alloc] init];
LLMineViewController *mineViewController = [[LLMineViewController alloc] init];UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = @[homeViewController, sameCityViewController, messageViewController, mineViewController];[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];LLTabBar *tabBar = [[LLTabBar alloc] initWithFrame:tabBarController.tabBar.bounds];
tabBar.tabBarItemAttributes = @[@{kLLTabBarItemAttributeTitle : @“首页”, kLLTabBarItemAttributeNormalImageName : @“home_normal”, kLLTabBarItemAttributeSelectedImageName : @“home_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
@{kLLTabBarItemAttributeTitle : @“同城”, kLLTabBarItemAttributeNormalImageName : @“mycity_normal”, kLLTabBarItemAttributeSelectedImageName : @“mycity_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
@{kLLTabBarItemAttributeTitle : @“发布”, kLLTabBarItemAttributeNormalImageName : @“post_normal”, kLLTabBarItemAttributeSelectedImageName : @“post_normal”, kLLTabBarItemAttributeType : @(LLTabBarItemRise)},
@{kLLTabBarItemAttributeTitle : @“消息”, kLLTabBarItemAttributeNormalImageName : @“message_normal”, kLLTabBarItemAttributeSelectedImageName : @“message_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
@{kLLTabBarItemAttributeTitle : @“我的”, kLLTabBarItemAttributeNormalImageName : @“account_normal”, kLLTabBarItemAttributeSelectedImageName : @“account_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)}];
// tabBar.tabBarItemAttributes = @[@{kLLTabBarItemAttributeTitle : @“首页”, kLLTabBarItemAttributeNormalImageName : @“home_normal”, kLLTabBarItemAttributeSelectedImageName : @“home_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
// @{kLLTabBarItemAttributeTitle : @“发布”, kLLTabBarItemAttributeNormalImageName : @“post_normal”, kLLTabBarItemAttributeSelectedImageName : @“post_normal”, kLLTabBarItemAttributeType : @(LLTabBarItemRise)},
// @{kLLTabBarItemAttributeTitle : @“消息”, kLLTabBarItemAttributeNormalImageName : @“message_normal”, kLLTabBarItemAttributeSelectedImageName : @“message_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)}];
// tabBar.tabBarItemAttributes = @[@{kLLTabBarItemAttributeTitle : @“首页”, kLLTabBarItemAttributeNormalImageName : @“home_normal”, kLLTabBarItemAttributeSelectedImageName : @“home_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
// @{kLLTabBarItemAttributeTitle : @“同城”, kLLTabBarItemAttributeNormalImageName : @“mycity_normal”, kLLTabBarItemAttributeSelectedImageName : @“mycity_highlight”, kLLTabBarItemAttributeType : @(LLTabBarItemNormal)}];
tabBar.delegate = self;
[tabBarController.tabBar addSubview:tabBar];
self.window.rootViewController = tabBarController;
return YES;
}
#pragma mark - LLTabBarDelegate
-
(void)tabBarDidSelectedRiseButton {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UIViewController *viewController = tabBarController.selectedViewController;UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@“取消”
destructiveButtonTitle:nil
otherButtonTitles:@“拍照”, @“从相册选取”, @“淘宝一键转卖”, nil];
[actionSheet showInView:viewController.view];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@“buttonIndex = %ld”, buttonIndex);
}
//
完毕,此实现是用别人的第三方类库