更改UIBarButtonItem的字体

时间:2012-11-19 08:46:03

标签: objective-c rubymotion

我正在使用Rubymotion构建iOS应用程序,我需要将字体系列设置为导航栏中按钮的自定义字体(UIBarButtonItem)。我知道我在Objective-C中这样做但是如何在Ruby中完成?

[buttonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica-Bold" size:26.0], UITextAttributeFont,nil] forState:UIControlStateNormal];

感谢所有人的帮助!

2 个答案:

答案 0 :(得分:2)

我认为这样做会。我没有把我的Mac用来测试它,所以试一试,让我们知道它是怎么回事。

buttonItem.setTitleTextAttributes({UITextAttributeFont => UIFont.fontWithName("Helvetica-Bold", size:26.0)}, forState:UIControlStateNormal)

答案 1 :(得分:2)

在你的AppDelegate中使用类似的东西

NSDictionary *itemTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [UIColor whiteColor],NSForegroundColorAttributeName,
                                    [UIColor whiteColor],NSBackgroundColorAttributeName,
                                    [UIFont fontWithName:@"Ubuntu-Regular" size:18],NSFontAttributeName,
                                    nil];

[[UIBarButtonItem appearance] setTitleTextAttributes:itemTextAttributes forState:UIControlStateNormal];