我是一位有用的助手,可以为您翻译文本。
我正在尝试给导航栏上添加的UI标签添加约束条件。该UI标签显示了一个持续运行的计时器。
这是我的代码:
当我运行应用程序时,我会收到错误消息“Cannot modify constraints for UINavigationBar managed by a controller”。我该如何添加此约束?
我正在尝试给导航栏上添加的UI标签添加约束条件。该UI标签显示了一个持续运行的计时器。
这是我的代码:
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]];
当我运行应用程序时,我会收到错误消息“Cannot modify constraints for UINavigationBar managed by a controller”。我该如何添加此约束?