Change font for UIBarButtonItem

I am building an iOS application using Rubymotion, and I need to set the font family to my own font for the button on the navigation bar (UIBarButtonItem). I know that I do it this way in Objective-C, but how is this done in Ruby?

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

Thanks for the help!

+4
source share
2 answers

I think it will be done. I don’t have my Mac to check this out, so give it a shot and let us know how it goes.

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

In AppDelegate app use something like this

 NSDictionary *itemTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],NSForegroundColorAttributeName, [UIColor whiteColor],NSBackgroundColorAttributeName, [UIFont fontWithName:@"Ubuntu-Regular" size:18],NSFontAttributeName, nil]; [[UIBarButtonItem appearance] setTitleTextAttributes:itemTextAttributes forState:UIControlStateNormal]; 
+2
source

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


All Articles