iOS Foundation: system font size

我们两清 提交于 2019-12-04 18:13:13

问题


I would like to know if systemFontSize in iOS app tableView is always the same for textLabel? This is are depening to style?

For example when I NSLog(@"%f",[UIFont systemFontSize]); I'm getting 14.0. Is this are always the same?

And what's more: How can i change font size without changing the font-family (assuming that i have my own fonts in my plist).

I tried:

cell.textLabel.font = [UIFont fontWithName:@"Sansation-Light" size:12.0];

But UIFont always want for me fontname/family. How can i avoid that and have one font to all my screen and changing only size?


回答1:


System Fonts are describe as following :

+ (CGFloat)labelFontSize;//Returns the standard font size used for labels.
+ (CGFloat)buttonFontSize;//Returns the standard font size used for buttons.
+ (CGFloat)smallSystemFontSize;//Returns the size of the standard small system font.
+ (CGFloat)systemFontSize;//Returns the size of the standard system font.

and you can change the font size without the font family like this :

cell.textLabel.font = [UIFont systemFontOfSize:14];



回答2:


System font sizes are not always the same. Beginning in iOS 7 there is Dynamic Type. Users can set their preferred font size in the system settings. This is the recommended way for apps to get and set their font sizes now.

In the Interface Builder you can choose things like Body or Title 1 under the Font settings. The actual size will be adjusted according to the user's system settings. Programmatically you use UIFont.preferredFont(forTextStyle: ). See this post for more details about doing this in iOS 10 and Swift 3.

See also

  • Typography docs
  • Text Programming Guide for iOS



回答3:


Just to add to the above answer. The above methods are members of UIFont class. So to get the default button font size...

float defaultFontSize = [UIFont buttonFontSize]; 


来源:https://stackoverflow.com/questions/10484211/ios-foundation-system-font-size

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