ios7 UINavigationBar setTitleTextAttributes crashes app

我的梦境 提交于 2019-12-13 01:00:33

问题


I wanted to set a consistent title colors for all my navigation bars:

NSDictionary *titleAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
                                  NSFontAttributeName: MY_FONT_HERE};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

This piece of code work in iOS6 but CRASH in ios7.

The crash message is bizarre:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-                 [__NSCFConstantString pointSize]: unrecognized selector sent to instance 0x107c34'

回答1:


I'm guessing that MY_FONT_HERE is a string value, when it should be a UIFont. Instead of passing in the string to the attributes, initialize the font with [UIFont fontWithName:MY_FONT_HERE].



来源:https://stackoverflow.com/questions/19036240/ios7-uinavigationbar-settitletextattributes-crashes-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!