【问题标题】:Remove border navigation bar buttons monotouch移除边框导航栏按钮单点触控
【发布时间】:2013-07-04 11:35:22
【问题描述】:

所以我在按钮上创建了一个带有图像的界面,但默认情况下,苹果会在导航栏按钮周围放置边框。有没有简单的方法来删除它们?

【问题讨论】:

    标签: c# ios xamarin.ios xamarin


    【解决方案1】:

    在您的界面构建器中选择一个按钮,然后在右列的属性上将其设为Custom 按钮,并带有背景图像:

    添加一个普通的 UIButton 后,你有一个简单的界面生成器警报(可以使用普通按钮),单击一个按钮并将其设置为自定义边框:

    在其他点击相同的按钮并设置第一个屏幕后;)

    【讨论】:

    • 这对于 UIBarButtons 是不可能的。
    • 在您的屏幕上,您不使用普通的 UIBarButton,而是使用普通的 UIButton 并拖入导航栏,因此如果不是这样,您可以使用普通的 UIButton 进入导航栏和设置,例如我的帖子从不添加更多代码;)我可以在帖子上添加一个屏幕来显示结果,并且可以像普通 UIButton 一样设置文本属性
    • 哦,好吧,我不知道你可以在导航栏添加一个普通的uibutton!我一定会试试的。
    • @FlorianSchaal thx,我添加了一个可能出现在界面生成器上的问题
    • 是的,我正在更改 UI 为 IOS7 做好准备。这样,该应用在 IOS6 和 IOS7 上的外观几乎相同;)
    【解决方案2】:

    根据Add custom button to navigation controller without border,你可以

    var button = new UIButton (new RectangleF (0, 0, 25, 25));
    button.SetImage (new UIImage ("image"), UIControlState.Normal);
    
    NavigationItem.LeftBarButtonItem = new UIBarButtonItem (button);
    

    当然,如果您想对 BarButtonItem 进行一些控制,您可以这样做:

    var button = new UIButton (new RectangleF (0, 0, 25, 25));
    button.SetImage (new UIImage ("image"), UIControlState.Normal);
    
    var buttonItem = new UIBarButtonItem (button);
    buttonItem.SetTitleTextAttributes(...);
    NavigationItem.LeftBarButtonItem = buttonItem;
    

    【讨论】:

    • 好的,这可行,但我将如何使用 SetTitleTextAttributes 呢?
    • 保留一个变量,指向您从 Button 创建的 UIBarButtonItem,您可以在该变量上调用 SetTitleTextAttribute
    • 嗯,我得到了这个错误:参数#1' cannot convert System.Drawing.RectangleF' 表达式输入`MonoTouch.UIKit.UIBarButtonSystemItem' (CS1503)
    • 我完成了回复,应该可以解决您的问题。
    猜你喜欢
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多