首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带额外填充iOS7的Monotouch - NavigationBar

带额外填充iOS7的Monotouch - NavigationBar
EN

Stack Overflow用户
提问于 2014-02-21 21:28:31
回答 2查看 183关注 0票数 0

我正在尝试让我的应用适应iOS 7。它是用Xamarin和C#编写的。

我在导航栏的左侧按钮的额外填充方面遇到了问题。

我有一个辅助方法来渲染我的后退按钮,如下所示:

代码语言:javascript
运行
复制
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,因为它会拉伸图像,使它变得丑陋。

有谁知道该怎么做吗?

EN

回答 2

Stack Overflow用户

发布于 2014-02-21 23:13:55

我试着查找你的问题,发现首先,你需要隐藏后退按钮,如下所示:

代码语言:javascript
运行
复制
NavigationItem.HidesBackButton = true;

然后为了设置按钮,你需要这样设置它:

代码语言:javascript
运行
复制
NavigationItem.BackBarButtonItem = yourButton;

那样的话,就不会有额外的缩进了。

此外,您可能会发现以下问题很有用:Make a custom back button for UINavigationController

票数 0
EN

Stack Overflow用户

发布于 2014-02-24 18:09:15

这就是我设置NavigationBar的方式

代码语言:javascript
运行
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21935772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档