我想與其他文本的UIBarButonSystemItem
(類似於例如UIBarButtonSystemItem.Cancel
)我的底部工具欄上。定製UIBarButtonSystemItem與其他文本
這是我現在有(代碼是在C#中,但它並不重要,因爲你可以在Objective-C提供解決方案):
UILabel markLabel = new UILabel (new RectangleF(0,0,150,30));
markLabel.Text = "Mark";
UIView containerView = new UIView (new RectangleF(0,0,150,30));
containerView.AddSubview (markLabel);
var markButton = new UIBarButtonItem (markLabel);
應該如何這樣的按鈕產生的呢?使用UIButton
(我這裏失敗)或UIView
與上面UILabel
?此外,我始終以提供框架性能。如果您想使用自動佈局,該怎麼辦?尺寸如何適應不斷變化的內容尺寸(例如國際化)以及間距元素呢?
編輯:
這現在與UIButton
:
var temp = UIButton.FromType (UIButtonType.System);
temp.SetTitle ("Mark", UIControlState.Normal);
temp.SizeToFit();
var markButton = new UIBarButtonItem (temp);
但顏色和字體大小必須適應。有些問題仍然存在:如果文本變得更寬,它不會縮小字體大小甚至AdjustsFontSizeToFitWidth
使用。定位也不同。例如。取消按鈕與屏幕邊框的間距不同於我的按鈕。
感謝Magicbjørn爲您解答。我得到它設法使用我在我的編輯發佈的解決方案。 'AdjustsFontSizeToFitWidth'和'SizeToFit'不能一起工作。你只能使用一個。隨着間距,我採取了負面的間隔。但以這種方式,我不必跟蹤屏幕尺寸。但有第二備份選項很不錯。 – testing 2015-01-07 08:06:14