ios - 如何更改 UIBarButtonItem 的上边距

标签 ios objective-c xamarin

我的 View 中有一个工具栏。它包含一个带有图标的条形按钮项目,实际上它不是图标(它是自定义字体)。我用它来统一同一客户的其他 Web 应用程序的图标。

无论如何,我怎样才能稍微增加上边距……也许给定的示例显示了一个过滤器图标,我可以轻松地将其替换为真实图像图标(不是字体)。但是其他一些图标,是不可能的。

Filter Icon in toolbar

编辑 1:

我正在使用 C# (Xamarin)。就算有object-c的代码。我同意。

var att = new UITextAttributes ();
att.Font = FontHelper.GetIconFont (32.0f);
this.btnFilter.SetTitleTextAttributes (att, UIControlState.Normal);

自定义图标字体方法:

public static UIFont GetIconFont(float size) 
{
    var nfloatSize = nfloat.Parse (((float)size).ToString ());
    return UIFont.FromName(_fontIcons, nfloatSize);
}

最佳答案

尝试这样的事情,

float offset = 3.0f;

UIBarButtonItem * barItem = [[UIBarButtonItem alloc] initWithTitle:@"title" 
                                                      style:UIBarButtonItemStyleDone
                                                      target:nil action:@selector(someMessage)];

[barItem setBackgroundVerticalPositionAdjustment:offset forBarMetrics:UIBarMetricsDefault];

关于ios - 如何更改 UIBarButtonItem 的上边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32327190/

相关文章:

ios - 如何在 Xamarin.Forms 中设置 ListView 行高

ios - 在 Xcode 中使用 webview 时,应用程序不会返回主登录目标页面

iphone - 缓出时间实现

objective-c - 使用 coredata 和多线程枚举时集合发生了变化

c# - Xamarin Build Error 编译无法完成,因为缺少一些库类

c# - 带秒的时间选择器

ios - 未调用 cellForRowAtIndexPath,行数、节数和单元格高度返回正确

ios - Swift:在删除之前将 View (用于应用内通知)动画显示到屏幕上几秒钟

ios - 在 NSUserDefaults 中设置默认设置。我做错了什么?

ios - 如果 UIWIndow 的 subview ,UIButton 单击不起作用