Appearance of UINavigationBar in RubyMotion not working

I am trying to customize the navigation bar in a RubyMotion application, but cannot change the font or color of the title text. I can set the background image and hue, but not the title attributes.

class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) navigationBar = UINavigationBar.appearance #navigationBar.setBackgroundImage(UIImage.imageNamed('navigation-bar-background.png'), forBarMetrics: UIBarMetricsDefault) #navigationBar.setTintColor(UIColor.greenColor) navigationBar.setTitleTextAttributes({ UITextAttributeFont: UIFont.fontWithName('Trebuchet MS', size:24), UITextAttributeTextShadowColor: UIColor.colorWithWhite(0.0, alpha:0.4), UITextAttributeTextColor: UIColor.blueColor }) puts navigationBar.titleTextAttributes.inspect @window.rootViewController = UINavigationController.alloc.initWithRootViewController(MainMenuController.alloc.init) @window.rootViewController.wantsFullScreenLayout = true @window.makeKeyAndVisible true end end 

The console output shows this for a validation instruction:

 {:UITextAttributeFont=>#<UICFFont:0x963aa70>, :UITextAttributeTextShadowColor=>UIColor.color(0x0, 0.0), :UITextAttributeTextColor=>UIColor.blueColor} 

So it seems that everything is set up correctly, but all I get is a standard blue navigation bar with white text.

+4
source share
1 answer

UITextAttributeFont etc. are valid constants, but when you use them in the new Ruby 1.9 hash assignment, it converts them to characters.

The easiest way is to use the old hash rocket destination style (do not force colons in front of UIText elements ...):

 navigationBar.setTitleTextAttributes({ UITextAttributeFont => UIFont.fontWithName('Trebuchet MS', size:24), UITextAttributeTextShadowColor => UIColor.colorWithWhite(0.0, alpha:0.4), UITextAttributeTextColor => UIColor.blueColor }) 
+15
source

Source: https://habr.com/ru/post/1443273/


All Articles