一、導(dǎo)航欄設(shè)置
1晰搀、導(dǎo)航欄背景顏色
在iOS 13及以上版本中蕉拢,使用UINavigationBarAppearance類來設(shè)置導(dǎo)航欄的樣式,而不再使用UINavigationBar的屬性刻两。因此增蹭,我們需要將樣式賦值給navigationBar的standardAppearance和scrollEdgeAppearance屬性,以確保導(dǎo)航欄在不同狀態(tài)下都能夠顯示正確的樣式
// 導(dǎo)航欄背景顏色
UIColor *navBarBgColor = [UIColor colorWithHexString:@"#F6F8FA"];
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *apperance = [[UINavigationBarAppearance alloc] init];
apperance.backgroundColor = navBarBgColor;
self.navigationBar.standardAppearance = apperance;
self.navigationBar.scrollEdgeAppearance = apperance;
} else {
self.navigationBar.barTintColor = navBarBgColor;
}
2磅摹、導(dǎo)航欄文本樣式
之所以適配版本是15滋迈,是因為在iOS 13UINavigationBar新增了scrollEdgeAppearance屬性,但在iOS 14及更早的版本中此屬性只應(yīng)用在大標題導(dǎo)航欄上户誓。在iOS 15中此屬性適用于所有導(dǎo)航欄饼灿。
// 導(dǎo)航欄標題文本樣式
NSDictionary *titleStyle = @{
NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName: [UIFont fontWithName:FontMedium size:19]
};
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *apperance = [[UINavigationBarAppearance alloc]init];
[apperance setTitleTextAttributes: titleStyle];
self.navigationBar.standardAppearance = apperance;
self.navigationBar.scrollEdgeAppearance = apperance;
} else {
self.navigationBar.titleTextAttributes = titleStyle;
}
``
####3、導(dǎo)航欄控件顏色:
self.navigationBar.tintColor = UIColor.redColor;
二帝美、Tabbar按鈕動效
通過tabBar: didSelectItem:代理方法接收每次點擊的item碍彭,對每個item都綁定動畫效果,獲取到的是item里面的UITabBarSwappableImageView圖片對象证舟。
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
}
// 添加tabbar點擊動畫
- (void)animationWithIndex:(NSInteger) index {
NSMutableArray * tabbarbuttonArray = [NSMutableArray array];
for (UIView *tabBarButton in self.customTabBar.subviews) {
if ([tabBarButton isKindOfClass:NSClassFromString(@"TYTGCarTabButton")]) {
[tabbarbuttonArray addObject:tabBarButton];
}
}
CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulse.duration = 0.2;
pulse.repeatCount= 1;
pulse.autoreverses= YES;
pulse.fromValue= [NSNumber numberWithFloat:0.9];
pulse.toValue= [NSNumber numberWithFloat:1.1];
UIView *TabBarButton = tabbarbuttonArray[index];
[TabBarButton.layer addAnimation:pulse forKey:nil];
}