HMTabBar .h文件如下。
#import <UIKit/UIKit.h>
@interface HMTabBar : UITabBar
@end
2、这里需要在.h中定义协议。定义的协议,和属性。@class HMTabBar;
@protocol HMTabBarDelegate <NSObject>//代理的名称:类名+Delegate
@optional
- (void)tabBarDidClickedPlusButton:(HMTabBar *)tabBar;//这是要代理要实现的方法。
@end
#import <UIKit/UIKit.h>
@class HMTabBar;
@protocol HMTabBarDelegate <NSObject>
@optional
- (void)tabBarDidClickedPlusButton:(HMTabBar *)tabBar;
@end
@interface HMTabBar : UITabBar
@property (nonatomic, weak) id<HMTabBarDelegate> delegate;
@end
// 通知代理
if ([self.delegate respondsToSelector:@selector(tabBarDidClickedPlusButton:)]) {
[self.delegate tabBarDidClickedPlusButton:self];
}
@interface HMTabBarViewController () <HMTabBarDelegate>
// 创建自定义tabbar
HMTabBar *customTabBar = [[HMTabBar alloc] init];
customTabBar.delegate = self;//设置代理。
#pragma mark - HMTabBarDelegate
- (void)tabBarDidClickedPlusButton:(HMTabBar *)tabBar
{
// 弹出发微博控制器
HMComposeViewController *compose = [[HMComposeViewController alloc] init];
HMNavigationController *nav = [[HMNavigationController alloc] initWithRootViewController:compose];
[self presentViewController:nav animated:YES completion:nil];
}
联系客服