简体   繁体   English

如何在 Swift 的大标题下创建小标题或小标题

[英]How to create Subtitle or Smaller Title under the Large title in Swift

I want to create aa title page that look similarly like on the Health App.我想创建一个类似于 Health App 的标题页。 It has Large title 'Summary' and a smaller title 'Favorites'它有一个大标题“摘要”和一个小标题“收藏夹”

健康应用

I'm able to create the Large title by Prefers Large Title.我可以通过 Prefers Large Title 来创建大标题。 But how do I create the smaller title like 'Favorites' in Health app?但是如何在健康应用程序中创建较小的标题,例如“收藏夹”?

Here's a look at my app:这是我的应用程序:

在此处输入图像描述

UPDATE:更新:

With the help of my friends here, I was able to create the header view closer to my expectation, but it needs a bit modification.在我朋友的帮助下,我能够创建更接近我预期的 header 视图,但需要进行一些修改。 Here's what it looks like now:这是它现在的样子: 新更新

Add a custom viewForHeader for your UITableView .为您的UITableView viewForHeader

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let label = UILabel()
    label.text = "Small title"
    label.font = .boldSystemFont(ofSize: 32) // give your required value here
    return label
}

This should work: Tested on iOS 13.5 (SwiftUI)这应该有效:在 iOS 13.5 (SwiftUI) 上测试

struct ContentView: View {
    
    var body: some View {
        VStack(){
            Text("Huge").font(.largeTitle)
            Text("Large").font(.title)
        }
    }
}

在此处输入图像描述

In the example you gave they also most likely had the modifier .bold()在您给出的示例中,他们也很可能具有修饰符.bold()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM