swift - 在 TabView 中更改 sf 符号的重量/大小
问题描述
这是一个示例 TabBar 代码:
struct TabBar: View{
@State var current = 0
var body: some View{
TabView(selection: $current) {
View0()
.tag(0)
.tabItem {
Image(systemName: "anySystemImageName")
Text("")
}
View1()
.tag(1)
.tabItem {
Image(systemName: "anySystemImageName")
Text("")
}
}
}
}
如何更改图标/文本的字体和大小?已经.font(.system(size: 30, weight: .bold))
在 Image(systemName: "Any") 和TabView
大括号之后尝试过,但都没有工作。
解决方案
您可以像这样更改标签栏的字体:
init() {
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .selected)
}
但是,我不知道您是否可以更改图像大小。我认为标签栏中的图标具有固定大小。不确定您是否可以更改它们UIKIt
编辑:您可以通过任何 UIFont。如果您想要不同的重量,可以使用 systemFont(ofSize: weight:) 像这样
UIFont.systemFont(ofSize: 20, weight: .bold)
推荐阅读
- jsf - inputCalendar forEach 调用异常
- c# - StackoverFlowException 从 ZipArchive 中创建 ZipArchive 时
- react-native - 如何从堆栈导航器中的屏幕导航到选项卡导航器
- amazon-web-services - 如何在aws上检测tomcat应用程序中的机器人流量
- vba - 使用 excel 宏“单击”按钮的宏帮助
- signalr - 将 JWT 令牌作为 QueryString 传递给 SignalR Hub
- angularjs - 我在访问 AngularJS 中的 $resource 变量时遇到问题
- c++ - 来自任何类的 c++ 函数对象/指针
- javascript - GM2 - 加载游戏时出现问题
- python - Pandas matplotlib 绘制多个子图