持续创造,加速成长!这是我参加「日新计划 10 月更文挑战」的第1天,点击查看活动概况
前言
技术完成关键点:经过layer.shadowOpacity
和View.layer.shadowOffset
完成
I 去掉TabBar的顶部黑线,添加发光的暗影
- setupshadowColor
- (void)setupshadowColor{
UIView * tmpView = self;
tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置暗影的色彩
tmpView.layer.shadowOpacity = 0.08;//设置暗影的透明度
tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(-5));//设置暗影的偏移量,暗影的大小,x往右和y往下是正
tmpView.layer.shadowRadius = kAdjustRatio(5);//设置暗影的圆角,//暗影的分散规模,相当于blur radius,也是shadow的突变间隔,从外围开端,往里突变shadowRadius间隔
//去掉TabBar的顶部黑线
[self setBackgroundImage:[UIImage createImageWithColor:[UIColor clearColor]]];
[self setShadowImage:[UIImage createImageWithColor:[UIColor clearColor]]];
}
II 给视图底部添加发光的暗影
2.1 作用
2.2 代码完成
- QCTShadowView
@implementation QCTShadowView
- (instancetype)init
{
self = [super init];
if (self) {
[self setupshadowColor];
//
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
[self layoutIfNeeded];
[self.layer layoutIfNeeded];
[self setupshadowColor];
}
- (void) setupshadowColor{
UIView * tmpView = self;
tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置暗影的色彩
tmpView.layer.shadowOpacity = 0.08;//设置暗影的透明度
tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(5));//设置暗影的偏移量,暗影的大小,x往右和y往下是正
tmpView.layer.shadowRadius = kAdjustRatio(5);//设置暗影的圆角,//暗影的分散规模,相当于blur radius,也是shadow的突变间隔,从外围开端,往里突变shadowRadius间隔
}
III、其他小知识点
3.1 防止selectedViewController视图被TabBar挡住
- 过错束缚
[_vcView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.offset(0);
}];
- 正确束缚
[_vcView mas_makeConstraints:^(MASConstraintMaker *make) {
[tmp mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.view).offset(0);
make.right.equalTo(weakSelf.view).offset(- 0);
make.top.equalTo(weakSelf.view).offset(0);
make.bottom.equalTo(weakSelf.view).offset(-weakSelf.tabBarController.tabBar.bounds.size.height);//防止视图被TabBar挡住
}];
}];
3.2 iOS 13适配深色模式【设置UITabBarItem上title色彩】
blog.csdn.net/z929118967/…
// 适配iOS13导致的bug
if (@available(iOS 13.0, *)) {
// iOS 13以上
// self.tabBar.tintColor = ;
self.tabBar.unselectedItemTintColor = ktabNorTextColor;
self.tabBar.tintColor = ktabSelectedTextColor;
// self.tabBar.unselectedItemTintColor = ;
// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffse/tMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
} else {
// // iOS 13以下
// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffsetMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0x999999)} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0xfb5400)} forState:UIControlStateSelected];
//设置文字样式
NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
textAttr[NSForegroundColorAttributeName] = ktabNorTextColor;
[childVC.tabBarItem setTitleTextAttributes:textAttr forState:UIControlStateNormal];
//挑选状态的文字色彩样式
NSMutableDictionary *selectedTextAttr = [NSMutableDictionary dictionary];
[selectedTextAttr setValue:ktabSelectedTextColor forKey:NSForegroundColorAttributeName];
[childVC.tabBarItem setTitleTextAttributes:selectedTextAttr forState:UIControlStateSelected];
}
3.3 适配安全区域间隔(safeAreaInsets)
blog.csdn.net/z929118967/…
使用场景1:自定义导航栏内容,导航栏显示公告和标题
使用场景2:自定义视图底部工具栏
使用场景3: 适配上拉加载更多控件 _vcView.tableView.mj_footer.ignoredScrollViewContentInsetBottom = k_ignoredScrollViewContentInsetBottom;
see also
iOS小技能:自定义导航栏,设置全局导航条外观。(iOS15适配) blog.csdn.net/z929118967/…