sách gpt4 ai đã đi

objective-c - 设置 UIView 子类的背景颜色不起作用

In lại 作者:可可西里 更新时间:2023-11-01 03:37:21 26 4
mua khóa gpt4 Nike

我正在尝试更改我的 UIView 子类之一的背景颜色。出于某种原因 self.backgroundColor = [UIColor whiteColor];当我将它放入我的 - (id)initWithFrame:(CGRect)frame 方法中时,它没有做任何事情看法。 View 始终是黑色的。我还从我的 View Controller 中尝试了 self.myView.backgroundColor ... ,但这也没有用。关于我做错了什么的任何想法?

相关代码如下所示:

[...]
@interface PaperView : UIView
[....]

[...]
@implementation PaperView
[...]

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[...]
// Initialization code
self.backgroundColor = [UIColor whiteColor]; // This doesn't do anything, the view is always black.
}
return self;
}

1 Câu trả lời

如果此 View 正在从 xib 中取消存档,则需要覆盖 -initWithCoder:. -initWithFrame: 仅在您以编程方式创建 View 时调用。

关于objective-c - 设置 UIView 子类的背景颜色不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8660480/

26 4 0
可可西里
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com