gpt4 book ai didi

ios - 定义基于 BOOL 的常量

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:04 24 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我有一个 constants.h 类,我在其中定义了 kBorderWidth。对于 Retina 显示器,我希望它为 0.5,这样边框的厚度为 1 个像素,而在非 Retina 显示器上,我希望它为 1,以便它保持一个像素的厚度而不是更少。这是我现在的代码:

#define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))

#if __IS_RETINA == 1
#define kBorderWidth .5
#else
#define kBorderWidth 1
#endif

这编译得很好,但导致 kBorderWidth 为 1。我该如何解决这个问题,以便它完成我想要它做的事情?

最佳答案

我确定的解决方案是 Lanorkin 建议的解决方案,它是这样定义的:

#define kBorderWidth (1.0 / [UIScreen mainScreen].scale)

这是面向 future 的,简单并且可以在我已经设置的 constants.h 文件中工作。

关于ios - 定义基于 BOOL 的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22124319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com