//色值
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
#define HEXCOLOR(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 green:((float)((hex & 0xFF00) >> 8)) / 255.0 blue:((float)(hex & 0xFF)) / 255.0 alpha:1]
/** 弱引用 */
#define WEAKSELF __weak typeof(self) weakSelf = self;
// 判断机型
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define kSCREEN_MAX_LENGTH (MAX(kScreenWidth, kScreenHeight))
#define kSCREEN_MIN_LENGTH (MIN(kScreenWidth, kScreenHeight))
// 判断型号
#define IS_IPHONE4 (IS_IPHONE && kSCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE5 (IS_IPHONE && kSCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE6 (IS_IPHONE && kSCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE6P (IS_IPHONE && kSCREEN_MAX_LENGTH == 736.0)
#define iPhoneX (kScreenWidth == 375.0f) && (kScreenHeight == 812.0f) && IS_IPHONE
///适配相关
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
#define kDeviceVersion [[UIDevice currentDevice].systemVersion floatValue]
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kSystemNavHeight 44.0
#define kNavbarHeight (kStatusBarHeight+kSystemNavHeight)
#define kTabBarHeight (iPhoneX?(49.f+34.f):(49.f))
#define kBottomSafeHeight ((iPhoneX)?(34):(0))
创建tabbar另一种方式
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *childItemsArray = @[
@{kClassKey : @"HomeViewController",
kTitleKey : @"微信",
kImgKey : @"tabbar_mainframe",
kSelImgKey : @"tabbar_mainframeHL"},
@{kClassKey : @"ContactsViewController",
kTitleKey : @"通讯录",
kImgKey : @"tabbar_contacts",
kSelImgKey : @"tabbar_contactsHL"},
@{kClassKey : @"DiscoverViewController",
kTitleKey : @"发现",
kImgKey : @"tabbar_discover",
kSelImgKey : @"tabbar_discoverHL"},
@{kClassKey : @"MeViewController",
kTitleKey : @"我",
kImgKey : @"tabbar_me",
kSelImgKey : @"tabbar_meHL"} ];
[childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
UIViewController *vc = [NSClassFromString(dict[kClassKey]) new];
vc.title = dict[kTitleKey];
BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
UITabBarItem *item = nav.tabBarItem;
item.title = dict[kTitleKey];
item.image = [UIImage imageNamed:dict[kImgKey]];
item.selectedImage = [[UIImage imageNamed:dict[kSelImgKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[item setTitleTextAttributes:@{NSForegroundColorAttributeName : kThemeColor} forState:UIControlStateSelected];
[self addChildViewController:nav];
}];
self.selectedIndex = 1;
}