UINavigationBar、UITabBar等样式修改

状态栏颜色修改

//在info.plist中添加View controller-based status bar appearance 并设置为NO
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

导航栏样式修改

// 修改导航栏标题字体样式 (颜色、字体、字号等)
NSDictionary *navbarTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]};
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
// 修改导航栏 返回和左右按钮的颜色
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
// 修改导航栏 背景颜色
 [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
// 获取导航栏底部黑线
__block UINavigationBar *weakBar = _twNavigationBar;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        if ([weakBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
            NSArray *list = weakBar.subviews;
            for (id obj in list) {
                if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) {
                    // IOS 10
                    NSString *classStr = NSStringFromClass([obj class]);
                    if ([classStr isEqualToString:@"_UIBarBackground"]) {
                        UIImageView *imageView = (UIImageView *)obj;
                        for (id obj2 in imageView.subviews) {
                            if ([obj2 isKindOfClass:[UIImageView class]]) {
                                UIImageView *imageView2=(UIImageView *)obj2;
                                imageView2.hidden = bl;
                            }
                        }
                    }
                }
                else {
                    if ([obj isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView=(UIImageView *)obj;
                        for (id obj2 in imageView.subviews) {
                            if ([obj2 isKindOfClass:[UIImageView class]]) {
                                UIImageView *imageView2=(UIImageView *)obj2;
                                imageView2.hidden = bl;
                            }
                        }
                    }
                }
            }
        }
    });

UITabBar

// 修改所有tabBarItem选中时图标和字体的颜色
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// 修改所有tabBarItem 各种状态(是否选中)是底部字体样式
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName: [UIFont systemFontOfSize:7]} forState:UIControlStateNormal];
// 修改UITabBar 是否透明
[[UITabBar appearance] setTranslucent:YES];
// 调整tabBarItem 文字偏移
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -6)];

输入框 修改光标颜色

[UISearchBar appearance].tintColor = [UIColor redColor];
[[UITextField appearance] setTintColor:[UIColor redColor]];
[[UITextView appearance]  setTintColor:[UIColor redColor]];

长按文字后的选择、全选按钮,,,添加自定义功能

// 类中需要使用 赋值、删除功能时,需要在类中实现 “copyText:” 和 “deleteObject:”方法
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setMenuVisible:YES animated:YES];
[menuController setMenuItems:@[
                               [[UIMenuItem alloc] initWithTitle:@"复制" action:NSSelectorFromString(@"copyText:")],
                               [[UIMenuItem alloc] initWithTitle:@"删除" action:NSSelectorFromString(@"deleteObject:")]
                                   ]];

你可能感兴趣的:(UINavigationBar、UITabBar等样式修改)