这就是我的屏幕应该是什么样子。它的底部有一个UIToolBar,并且包含一个UIBarButtonItem。在iOS 11之前,它工作得很好。
但在iOS 11中,UIBarButtonItem正在展示自己的位置。它将显示在状态栏中。在模拟器中,它工作正常,并且在工具栏中显示。但当我在运行iOS 11的iPhone 6s上运行它时,它的显示如下图所示。
这是代码..
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
UIBarButtonItem[] bArray = {
getSetAsHomeButton(apiCall, this, 0),
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
};
SetToolbarItems(bArray, true);
}
public static UIBarButtonItem getSetAsHomeButton(ICommonApiCall commonApiCall, UIViewController controller, int status)
{
var view = new UIButton ();
view.Layer.CornerRadius = 8;
view.BackgroundColor = UIColor.White;
view.TranslatesAutoresizingMaskIntoConstraints = false;
view.WidthAnchor.ConstraintEqualTo(108).Active = true;
view.HeightAnchor.ConstraintEqualTo(32).Active = true;
var HomeIcon = new UILabel (new RectangleF (0, 0, 21, 21));
HomeIcon.Font = FontAwesome.Font (22);
HomeIcon.Text = FontAwesome.FAHome;
HomeIcon.TextColor = PlatformConstants.PrimaryColor;
var HomeLabel = new UILabel (new RectangleF (25, 0, 64, 44));
HomeLabel.Text = "Set as default";
HomeLabel.Font = UIFont.FromName (PlatformConstants.PrimaryFont + "-Medium", 11);
HomeLabel.TextColor = PlatformConstants.PrimaryColor;
HomeLabel.Lines = 0;
HomeLabel.SizeToFit ();
view.AddSubview (HomeIcon);
view.AddSubview (HomeLabel);
HomeIcon.TranslatesAutoresizingMaskIntoConstraints = false;
HomeLabel.TranslatesAutoresizingMaskIntoConstraints = false;
var hSpaceLeading = NSLayoutConstraint.Create (HomeIcon, NSLayoutAttribute.Leading,
NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1, 6);
view.AddConstraint (hSpaceLeading);
var HomeIconCenterY = NSLayoutConstraint.Create (HomeIcon, NSLayoutAttribute.CenterY,
NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterY, 1, 0);
view.AddConstraint (HomeIconCenterY);
var HomeLabelCenterY = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.CenterY,
NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterY, 1, 0);
view.AddConstraint (HomeLabelCenterY);
var hSpace = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.Left,
NSLayoutRelation.Equal, HomeIcon, NSLayoutAttribute.Right, 1, 4);
view.AddConstraint (hSpace);
var HomeLabelWidth = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.Width,
NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 80);
view.AddConstraint (HomeLabelWidth);
view.LayoutIfNeeded ();
view.TouchUpInside += delegate {
SetAsHome (commonApiCall, controller, status, view).ContinueWith (t => Console.WriteLine (t.Exception),
TaskContinuationOptions.OnlyOnFaulted);
};
return new UIBarButtonItem (view);
}
任何帮助都是非常感谢的。谢谢。
发布于 2017-10-10 16:54:13
因为在UINavigationBar和UIToolbar元素中引入了iOS自动布局。因此,解决问题的最好方法是添加适当的约束。
在这里您可以找到有关该问题的更多帮助和详细信息:https://forums.developer.apple.com/thread/80075
希望这能解决你的问题。
https://stackoverflow.com/questions/46514903
复制相似问题