gpt4 book ai didi

ios - 抓取 iPhone screenWidth 和 Height 以实现可重用性

转载 作者:行者123 更新时间:2023-11-28 22:26:26 24 4
gpt4 key购买 nike

我像这样创建了一个类别:

#import "UIViewController+Dimensions.h"

@implementation UIView (Dimensions)

- (double) screenWidth2
{
return self.frame.size.width;
}

- (double) screenHeight2
{
return self.frame.size.height;
}


@end

但是当我在导入它之后尝试在我的 View Controller 中调用它时,我得到:

"Use of undeclared identifier screenWidth2;

有没有比我所在的每个 View Controller 更好的方法来在一个地方获取 screenWidth?

然后我在我的 View Controller 中做了这个:

 _registerButton.frame = CGRectMake(0.0, 0.0, [self screenWidth2] / 2.0 - 1.0, 60.0);

但应用程序编译运行并崩溃。该类别的 .h 文件是:

#import <UIKit/UIKit.h>

@interface UIViewController (Dimensions)

- (double) screenWidth2;

- (double) screenHeight2;

@end

最佳答案

你需要添加

#import "UIViewController+Dimensions.h"

在使用类别的代码中(调用[uiViewControllerInstance screenWidth2]的文件)

关于ios - 抓取 iPhone screenWidth 和 Height 以实现可重用性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18823379/

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