我正在尝试让我的应用适应iOS 7。它是用Xamarin和C#编写的。
我在导航栏的左侧按钮的额外填充方面遇到了问题。
我有一个辅助方法来渲染我的后退按钮,如下所示:
public static UIBarButtonItem GetBackButton (this UIViewController controller)
{
var backImage = new UIImage ("Images/back.png");
var backButton = new UIButton (UIButtonType.Custom);
backButton.Frame = new RectangleF (0, 0, 44, 44);
backButton.SetImage (backImage, UIControlState.Normal);
backButton.TouchUpInside += (object sender, EventArgs e) => {
var cancelBackNavigation = false;
if (controller is UIViewControllerBase) {
if (((UIViewControllerBase)controller).PrepareNavigateBack () != true) {
cancelBackNavigation = true;
}
}
if (cancelBackNavigation == false) {
controller.NavigationController.PopViewControllerAnimated (true);
}
};
return new UIBarButtonItem (backButton);
}
导航栏在后退按钮之前添加了很多填充,使得后退按钮内部的图像看起来离它的实际位置很远。上面的代码在iOS 6中运行良好。
我不想使用ContentEdgeInsets,因为它会拉伸图像,使它变得丑陋。
有谁知道该怎么做吗?
发布于 2014-02-21 23:13:55
我试着查找你的问题,发现首先,你需要隐藏后退按钮,如下所示:
NavigationItem.HidesBackButton = true;
然后为了设置按钮,你需要这样设置它:
NavigationItem.BackBarButtonItem = yourButton;
那样的话,就不会有额外的缩进了。
此外,您可能会发现以下问题很有用:Make a custom back button for UINavigationController
发布于 2014-02-24 18:09:15
这就是我设置NavigationBar的方式
controller.View.BackgroundColor = Theme.BackgroundColor;
controller.NavigationItem.SetHidesBackButton (true, false);
controller.NavigationController.Toolbar.TintColor = Theme.BackgroundColor;
controller.NavigationController.NavigationBar.TintColor = Theme.BackgroundColor;
controller.NavigationController.SetNavigationBarHidden (show == false, false);
controller.NavigationController.NavigationBar.BackgroundColor = Theme.BackgroundColor;
controller.NavigationController.NavigationBar.SetTitleTextAttributes (Theme.NavigationBarTextAttributes);
controller.NavigationController.NavigationBar.Subviews [0].Alpha = 0.01f;
https://stackoverflow.com/questions/21935772
复制相似问题