gpt4 book ai didi

ios - addSubview 不显示 UIView

转载 作者:行者123 更新时间:2023-12-01 17:53:41 24 4
gpt4 key购买 nike

我描述了[self.view addSubView:myView]; ,
但是,myView 不显示 self.view .

View Controller .h

@interface ViewController : UIViewController{
UIView *myView;
}

@property (nonatomic, strong) UIView *myView;

View Controller .m
@synthesize myView;

- (void)viewDidLoad
{
[super viewDidLoad];

myView.frame = CGRectMake(-10, 70, 320, 480);
[self.view addSubview:myView];
myView.backgroundColor = [UIColor redColor];
[self.view bringSubviewToFront:myView];
}

你有什么解决办法?

最佳答案

您需要先分配 View :

- (void)viewDidLoad
{
[super viewDidLoad];

// If you use custom view change UIView to the custom class name
myView = [[UIView alloc] initWithFrame:CGRectMake(-10, 70, 320, 480)];

[self.view addSubview:myView];
myView.backgroundColor = [UIColor redColor];
[self.view bringSubviewToFront:myView];
}

关于ios - addSubview 不显示 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22064723/

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