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

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

      1. <legend id='pyq9g'><style id='pyq9g'><dir id='pyq9g'><q id='pyq9g'></q></dir></style></legend>
        • <bdo id='pyq9g'></bdo><ul id='pyq9g'></ul>

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

        如何在 UINavigationController 中添加多行标题栏

        时间:2023-06-11
        <i id='hgUMX'><tr id='hgUMX'><dt id='hgUMX'><q id='hgUMX'><span id='hgUMX'><b id='hgUMX'><form id='hgUMX'><ins id='hgUMX'></ins><ul id='hgUMX'></ul><sub id='hgUMX'></sub></form><legend id='hgUMX'></legend><bdo id='hgUMX'><pre id='hgUMX'><center id='hgUMX'></center></pre></bdo></b><th id='hgUMX'></th></span></q></dt></tr></i><div id='hgUMX'><tfoot id='hgUMX'></tfoot><dl id='hgUMX'><fieldset id='hgUMX'></fieldset></dl></div>

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

          <tbody id='hgUMX'></tbody>

              <bdo id='hgUMX'></bdo><ul id='hgUMX'></ul>
              <legend id='hgUMX'><style id='hgUMX'><dir id='hgUMX'><q id='hgUMX'></q></dir></style></legend>

                • <tfoot id='hgUMX'></tfoot>
                • 本文介绍了如何在 UINavigationController 中添加多行标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试在 UINavigationController 中添加两行标题栏

                  I have try to add a two line title bar in UINavigationController

                  我想根据字符串长度自动调整字体大小.我的字符串最大大小变为60.我尝试通过以下代码实现

                  I want to adjust font size automatically set according to string length.My String max size goes to 60. I have try to implemented through following code

                  UILabel *bigLabel = [[UILabel alloc] init];
                  bigLabel.text = @"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
                  bigLabel.backgroundColor = [UIColor clearColor];
                  bigLabel.textColor = [UIColor whiteColor];
                  bigLabel.font = [UIFont boldSystemFontOfSize:20];
                  bigLabel.adjustsFontSizeToFitWidth = YES;
                  bigLabel.clipsToBounds = NO;
                  bigLabel.numberOfLines = 2;
                  bigLabel.textAlignment = ([self.title length] < 10 ? NSTextAlignmentCenter : NSTextAlignmentLeft);
                  [bigLabel sizeToFit];
                  
                  self.navigationItem.titleView = bigLabel;
                  

                  这对我不起作用,请你帮帮我.我必须为 iPhone 和 iPad 屏幕制作这个

                  It didn't work for me can you help me please. I have to made this for iPhone and iPad screen

                  推荐答案

                  只需设置 UILabelsetNumberOfLines: 0.请参阅下面的示例.

                  Just set setNumberOfLines: 0 of UILabel. See the example below.

                  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
                  [label setBackgroundColor:[UIColor clearColor]];
                  [label setNumberOfLines:0];
                  [label setTextColor:[UIColor whiteColor]];
                  [label setTextAlignment:NSTextAlignmentCenter];
                  [label setText:@"1234567890 1234567890 1234567890 1234567890 1234567890 123456"];
                  self.navigationItem.titleView = label;
                  

                  设置左右 UIBarButtonItems - 你可以添加它们.

                  Set Left and Right UIBarButtonItems - you can add them.

                  UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(leftPress:)];
                  self.navigationItem.leftBarButtonItem = leftBarButton;
                  
                  UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(rightPress:)];
                  self.navigationItem.rightBarButtonItem = rightBarButton;
                  

                  同时减小LabelFontSize.在这种情况下是 12.它看起来像这样:

                  Also decrease the FontSize of Label. It is 12 in this case. And it will look like this:

                  关于扩展问题:

                  只需对之前的代码进行一些更改 -

                  Just make some changes in previous code -

                  [label setNumberOfLines:2]; //Set it 2 instead of 0
                  
                  NSString *titleStr = @"3456456676456464554541223434484384233456744444444456785643367";
                  
                  //Check your string length then set font according to it.
                  //I have set font size according to your requirement
                  //which is 0-60.
                  
                  if([titleStr length]>40 && [titleStr length]<=52){
                      [label setFont:[UIFont fontWithName:@"Arial" size:13.0]];
                  }
                  else if([titleStr length]>52){
                      [label setFont:[UIFont fontWithName:@"Arial" size:11.5]];
                  }
                  
                  [label setText:titleStr];
                  

                  注意:您不能使用 UILabeladjustsFontSizeToFitWidth: 属性,因为它不适用于 setNumberOfLines:0 在您的情况下,您将不得不使用 if 条件来处理它.

                  Note: You can't use adjustsFontSizeToFitWidth: property of UILabel, because it doesn't work for setNumberOfLines:0 in your case you will have to handle it with if condition.

                  这是根据width设置fontSizeUILabel的方法.

                  This is method for set fontSize Of UILabel according to its width.

                  [label setNumberOfLines:1];
                  label.adjustsFontSizeToFitWidth = YES;
                  label.minimumFontSize = 1.0;
                  

                  这篇关于如何在 UINavigationController 中添加多行标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:翻转过渡 uinavigationcontroller push 下一篇:在自定义模式中呈现 UINavigationController

                  相关文章

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

                  1. <small id='3UWVL'></small><noframes id='3UWVL'>

                    1. <legend id='3UWVL'><style id='3UWVL'><dir id='3UWVL'><q id='3UWVL'></q></dir></style></legend><tfoot id='3UWVL'></tfoot>