UINavigationBar、UITabBar等樣式修改

狀態(tài)欄顏色修改

//在info.plist中添加View controller-based status bar appearance 并設(shè)置為NO
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

導(dǎo)航欄樣式修改

// 修改導(dǎo)航欄標(biāo)題字體樣式 (顏色、字體、字號(hào)等)
NSDictionary *navbarTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]};
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
// 修改導(dǎo)航欄 返回和左右按鈕的顏色
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
// 修改導(dǎo)航欄 背景顏色
 [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
// 獲取導(dǎo)航欄底部黑線
__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選中時(shí)圖標(biāo)和字體的顏色
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// 修改所有tabBarItem 各種狀態(tài)(是否選中)是底部字體樣式
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName: [UIFont systemFontOfSize:7]} forState:UIControlStateNormal];
// 修改UITabBar 是否透明
[[UITabBar appearance] setTranslucent:YES];
// 調(diào)整tabBarItem 文字偏移
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -6)];

輸入框 修改光標(biāo)顏色

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

長(zhǎng)按文字后的選擇、全選按鈕,,,添加自定義功能

// 類中需要使用 賦值、刪除功能時(shí),需要在類中實(shí)現(xiàn) “copyText:” 和 “deleteObject:”方法
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setMenuVisible:YES animated:YES];
[menuController setMenuItems:@[
                               [[UIMenuItem alloc] initWithTitle:@"復(fù)制" action:NSSelectorFromString(@"copyText:")],
                               [[UIMenuItem alloc] initWithTitle:@"刪除" action:NSSelectorFromString(@"deleteObject:")]
                                   ]];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容