我想在UINavigationBar
的位置leftBarButtonItem
/rightBarButtonItem
上设置文本。您必须使用UIBarButtonItem
,但您可以将不同的UIView
对象放入其中。首先,我尝试使用标签,但这不起作用。代码是用C#编写的,但你应该明白:导航栏中的自定义文本
UILabel textLabel = new UILabel();
textLabel.Text = "My custom text which should be displayed in navigation bar";
UIBarButtonItem customBarButtonItem = new UIBarButtonItem (textLabel);
NavigationItem.RightBarButtonItem = customBarButtonItem;
该标签不显示。如果我使用的按钮似乎工作(除了样式必须适应)。
UIBarButtonItem customBarButtonItem = new UIBarButtonItem ("My custom text which should be displayed in navigation bar", UIBarButtonItemStyle.Plain,null);
NavigationItem.RightBarButtonItem = customBarButtonItem;
为什么不可以使用UILabel
?在UIBarButtonItem
中显示文本的正确方式是什么?
编辑:
我目前的研究结果是:
任一组的UIBarButtonItem
标题或设置UILabel
(感谢Anbu.Karthik此)的框架上。
您更好地展现真正的代码,并坚持命名约定。这是相当猜测的工作。 –
@HermannKlecker:我编辑了我的问题以获得更多有意义的占位符。该代码是我想以后使用的。只有内容会改变。 – testing