为UIFont定义宏不起作用 [英] Define macro for UIFont doesn't work
本文介绍了为UIFont定义宏不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想定义一个宏来统一我的应用中的所有字体:
I want define a macro for unifying all fonts in my app:
#define EXO_REGULAR_FONT(size) [UIFont fontWithName:@"Exo-Regular" size:size]
而不是像这样使用这个宏:
and than using this macro like this:
myLabel.font = EXO_REGULAR_FONT(15);
但编译器给我这个错误:
But the compiler give me this error:
(有) 15岁以下的箭头。
(there is an arrow under 15).
要解决的想法是什么?谢谢
Any ideas to resolve ? Thanks
推荐答案
更改参数名称:
#define EXO_REGULAR_FONT(theFontSize) [UIFont fontWithName:@"Exo-Regular" size:theFontSize]
来自 GCC手册:
扩展宏时,其主体中每个参数的使用都被相应参数的标记替换
When the macro is expanded, each use of a parameter in its body is replaced by the tokens of the corresponding argument
因此当您的宏展开时,它会在您的代码中插入它,因此编译错误:
So when your macro is expanded, it inserts this in your code, hence the compilation error:
[UIFont fontWithName:@"Exo-Regular" 15:15]
这篇关于为UIFont定义宏不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文