1. <small id='2CYQr'></small><noframes id='2CYQr'>

      <tfoot id='2CYQr'></tfoot>
      • <bdo id='2CYQr'></bdo><ul id='2CYQr'></ul>
      1. <legend id='2CYQr'><style id='2CYQr'><dir id='2CYQr'><q id='2CYQr'></q></dir></style></legend>
        <i id='2CYQr'><tr id='2CYQr'><dt id='2CYQr'><q id='2CYQr'><span id='2CYQr'><b id='2CYQr'><form id='2CYQr'><ins id='2CYQr'></ins><ul id='2CYQr'></ul><sub id='2CYQr'></sub></form><legend id='2CYQr'></legend><bdo id='2CYQr'><pre id='2CYQr'><center id='2CYQr'></center></pre></bdo></b><th id='2CYQr'></th></span></q></dt></tr></i><div id='2CYQr'><tfoot id='2CYQr'></tfoot><dl id='2CYQr'><fieldset id='2CYQr'></fieldset></dl></div>

        在Xcode导航栏控制器的标题下添加字幕

        时间:2023-05-17

          • <i id='IS2AG'><tr id='IS2AG'><dt id='IS2AG'><q id='IS2AG'><span id='IS2AG'><b id='IS2AG'><form id='IS2AG'><ins id='IS2AG'></ins><ul id='IS2AG'></ul><sub id='IS2AG'></sub></form><legend id='IS2AG'></legend><bdo id='IS2AG'><pre id='IS2AG'><center id='IS2AG'></center></pre></bdo></b><th id='IS2AG'></th></span></q></dt></tr></i><div id='IS2AG'><tfoot id='IS2AG'></tfoot><dl id='IS2AG'><fieldset id='IS2AG'></fieldset></dl></div>

              1. <tfoot id='IS2AG'></tfoot>

                • <bdo id='IS2AG'></bdo><ul id='IS2AG'></ul>

                  <legend id='IS2AG'><style id='IS2AG'><dir id='IS2AG'><q id='IS2AG'></q></dir></style></legend>
                    <tbody id='IS2AG'></tbody>
                • <small id='IS2AG'></small><noframes id='IS2AG'>

                  本文介绍了在Xcode导航栏控制器的标题下添加字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  所以我想在导航控制器导航栏的标题下添加一个副标题".

                  到目前为止,我查找的大部分内容都希望我使用 CGRect.我不太清楚那是什么,听起来它想让我创建一个全新的视图,这不是我想做的.

                  我的问题是,有没有一种点法可以轻松添加字幕视图?

                  我发现的最接近的东西是在堆栈溢出上发布的,这是链接:

                  来源:https://gist.github.com/nazywamsiepawel/0166e8a71d74e96c7898

                  So I'm wanting to add a "subtitle" under the title in the navigation bar in navigation controller.

                  Mostly everything I look up so far wants me to use CGRect. I don't know a whole lot what that is and it sounds like its wanting me to create an entire new view which is not what I am wanting to do.

                  My question is, is there a dot method to adding a subtitle view easily?

                  The closest thing I found was posted on stack overflow and here is the link:

                  Create a subtitle in navigationbar

                  Apparently last year this worked but now I am getting errors and it's in my viewDidLoad...

                  I tried this:

                  self.navigationController?.navigationItem.prompt = "Subtitle Here"

                  It's the only thing that won't show any errors but still doesn't work. It literally does nothing. At least nothing visible at run time.

                  On a side note, swift is preferred. Thanks!

                  解决方案

                  Though there is a solution but it has some known issues

                  Solution is writing a function like this

                  func setTitle(title:String, subtitle:String) -> UIView {
                      let titleLabel = UILabel(frame: CGRectMake(0, -2, 0, 0))
                  
                      titleLabel.backgroundColor = UIColor.clearColor()
                      titleLabel.textColor = UIColor.grayColor()
                      titleLabel.font = UIFont.boldSystemFontOfSize(17)
                      titleLabel.text = title
                      titleLabel.sizeToFit()
                  
                      let subtitleLabel = UILabel(frame: CGRectMake(0, 18, 0, 0))
                      subtitleLabel.backgroundColor = UIColor.clearColor()
                      subtitleLabel.textColor = UIColor.blackColor()
                      subtitleLabel.font = UIFont.systemFontOfSize(12)
                      subtitleLabel.text = subtitle
                      subtitleLabel.sizeToFit()
                  
                      let titleView = UIView(frame: CGRectMake(0, 0, max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), 30))
                      titleView.addSubview(titleLabel)
                      titleView.addSubview(subtitleLabel)
                  
                      let widthDiff = subtitleLabel.frame.size.width - titleLabel.frame.size.width
                  
                      if widthDiff < 0 {
                          let newX = widthDiff / 2
                          subtitleLabel.frame.origin.x = abs(newX)
                      } else {
                          let newX = widthDiff / 2
                          titleLabel.frame.origin.x = newX
                      }
                  
                      return titleView
                  }
                  

                  Using this function for custom navigation title view in viewDidLoad

                  self.navigationItem.titleView = setTitle("Title", subtitle: "SubTitle")
                  

                  Only known issue is that if subtitle becomes very large than the misplacement occurs.

                  Final Outcome

                  Source: https://gist.github.com/nazywamsiepawel/0166e8a71d74e96c7898

                  这篇关于在Xcode导航栏控制器的标题下添加字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:InputAccessoryView 停靠在底部 下一篇:Swift – 在 App Delegate 中实例化没有故事板的导航控制器

                  相关文章

                • <legend id='sWibQ'><style id='sWibQ'><dir id='sWibQ'><q id='sWibQ'></q></dir></style></legend>

                    <small id='sWibQ'></small><noframes id='sWibQ'>

                      • <bdo id='sWibQ'></bdo><ul id='sWibQ'></ul>

                    1. <i id='sWibQ'><tr id='sWibQ'><dt id='sWibQ'><q id='sWibQ'><span id='sWibQ'><b id='sWibQ'><form id='sWibQ'><ins id='sWibQ'></ins><ul id='sWibQ'></ul><sub id='sWibQ'></sub></form><legend id='sWibQ'></legend><bdo id='sWibQ'><pre id='sWibQ'><center id='sWibQ'></center></pre></bdo></b><th id='sWibQ'></th></span></q></dt></tr></i><div id='sWibQ'><tfoot id='sWibQ'></tfoot><dl id='sWibQ'><fieldset id='sWibQ'></fieldset></dl></div>
                      <tfoot id='sWibQ'></tfoot>