swift新手入门随手笔记

本文介绍了如何在SwiftUI中自定义TabBarController的图标及文字颜色,并提供了详细的代码示例,包括修改图标颜色、文字颜色、导航栏字体颜色、导航栏背景颜色以及返回按钮颜色的方法。

1、创建tabBarController的图片和文字颜色都是蓝色的 修改图片颜色方法:

var image:UIImage = UIImage(named: "shouye-weixuanzhong")!

var selectedImage:UIImage = UIImage(named: "shouye")!

image = image.withRenderingMode(UIImageRenderingMode.alwaysOriginal)

selectedImage = selectedImage.withRenderingMode(UIImageRenderingMode.alwaysOriginal)

homeVC.tabBarItem.image = image

PS:

public enum UIImageRenderingMode : Int {

                                    case automatic // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式

            case alwaysOriginal // 始终绘制图片原始状态,不使用

            Tint Color case alwaysTemplate //始终根据Tint Color绘制图片,忽略图片的颜色信息

}

2、修改文字颜色的方式

homeVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.red], for: .highlighted) homeVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.black], for: .normal) 

 

3、修改原生导航栏上字体颜色

navigationController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.red]

4、修改原生导航栏的颜色

navigationController.navigationBar.barTintColor = UIColor.yellow

5、修改左右返回按钮颜色

navigationController.navigationBar.tintColor = UIColor.yellow

新手入门,欢迎大家交流讨论

转载于:https://www.cnblogs.com/guangdingaoaopa/p/7097640.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值