• <small id='NC0f1'></small><noframes id='NC0f1'>

      <i id='NC0f1'><tr id='NC0f1'><dt id='NC0f1'><q id='NC0f1'><span id='NC0f1'><b id='NC0f1'><form id='NC0f1'><ins id='NC0f1'></ins><ul id='NC0f1'></ul><sub id='NC0f1'></sub></form><legend id='NC0f1'></legend><bdo id='NC0f1'><pre id='NC0f1'><center id='NC0f1'></center></pre></bdo></b><th id='NC0f1'></th></span></q></dt></tr></i><div id='NC0f1'><tfoot id='NC0f1'></tfoot><dl id='NC0f1'><fieldset id='NC0f1'></fieldset></dl></div>
        <legend id='NC0f1'><style id='NC0f1'><dir id='NC0f1'><q id='NC0f1'></q></dir></style></legend><tfoot id='NC0f1'></tfoot>
          <bdo id='NC0f1'></bdo><ul id='NC0f1'></ul>
      1. 以编程方式向导航控制器添加自动布局约束

        时间:2023-09-10
          <tbody id='pFOjJ'></tbody>

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

            <legend id='pFOjJ'><style id='pFOjJ'><dir id='pFOjJ'><q id='pFOjJ'></q></dir></style></legend>

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

                  <tfoot id='pFOjJ'></tfoot>
                  本文介绍了以编程方式向导航控制器添加自动布局约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将约束添加到我在导航栏上添加的 UI 标签.UI 标签显示一个正在运行的计时器

                  I am trying to add constraints to a UI label I added on a navigation bar. The UI label shows a running timer

                  这是我的代码,

                  self.label = [[UILabel alloc] initWithFrame:CGRectMake(550, 15, 150, 14)];
                  self.label.text = @"Label";
                  [self.label setTranslatesAutoresizingMaskIntoConstraints:NO];
                  [self.navigationController.navigationBar addSubview:self.label];
                  
                  [self.navigationController.navigationBar addConstraint:[NSLayoutConstraint constraintWithItem:self.label
                                                                         attribute:NSLayoutAttributeTrailing
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.navigationController.navigationBar
                                                                         attribute:NSLayoutAttributeTrailing
                                                                        multiplier:1.0f
                                                                          constant:-20.0f]];
                  

                  但我在运行应用程序时收到错误消息无法修改控制器管理的 UINavigationBar 的约束".

                  But I get the error 'Cannot modify constraints for UINavigationBar managed by a controller' when I run the app.

                  如何添加此约束?

                  推荐答案

                  简而言之:你不能.

                  导航控制器管理导航栏和可选导航工具栏的创建、配置和显示.允许自定义导航栏与外观相关的属性,但绝不能直接更改其框架、边界或 alpha 值……导航控制器使用导航项对象(UINavigationItem 的实例)动态构建导航栏的内容类)与导航堆栈上的视图控制器相关联

                  The navigation controller manages the creation, configuration, and display of the navigation bar and optional navigation toolbar. It is permissible to customize the navigation bar’s appearance-related properties but you must never change its frame, bounds, or alpha values directly ... A navigation controller builds the contents of the navigation bar dynamically using the navigation item objects (instances of the UINavigationItem class) associated with the view controllers on the navigation stack

                  来源:Apple Docs

                  您需要将 UINavigationBar 子类化,然后使用 initWithNavigationBarClass:toolbarClass: 实例化 UINavigationController 以做进一步的事情.

                  You would need to subclass the UINavigationBar and then instantiate the UINavigationController using initWithNavigationBarClass:toolbarClass: to do something further.

                  如果您正在寻找自定义导航栏的方法,UIKit 用户界面指南 是了解您可以做什么的良好开端.但是,如果它将是一个文本标签,请考虑设置栏的 title 属性,例如.

                  Though if you're looking for ways to customize the navbar, UIKit User Interface Guide is a good start to know what you may be able to do. But if it's going to be a text label, consider setting the bar's title property, for example.

                  这篇关于以编程方式向导航控制器添加自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UITableViewCell 中 UILabel 的不明确布局警告 下一篇:向 UIBarButtonItem 添加约束

                  相关文章

                    <bdo id='yvuEM'></bdo><ul id='yvuEM'></ul>

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

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