我有一个非常简单的 UIView 来创建盒子,但是 UIView 根本没有显示,这是我在 sharingButtons.m
-(void)createContainer{
winWidth = [UIScreen mainScreen].bounds.size.width;
buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, winWidth, 20)];
buttonContainer.backgroundColor = [UIColor redColor];
[self.view addSubview:buttonContainer];
}
-(void)createButton{
[self createContainer];
}
这是我的sharingButtons.h
@interface SocialSharing : UIViewController {
int winWidth;
}
- (void)createButton;
- (void)createContainer;
#pragma mark - Properties
@property(nonatomic, strong) UIView* buttonContainer;
@end
并且 createButton
方法在 viewDidLoad
上从 MyViewControler.m
调用
我的代码有问题吗??
已编辑
这是我在 MyViewControler.m 上的代码
- (void)loadSocialSharingButton {
socialButtons = [[SocialSharing alloc] init];
[socialButtons createButton];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadSocialSharingButton];
}
抱歉,我刚刚了解 obj c :)
非常感谢
最佳答案
您的 buttonContainer
不可见的原因是,它没有加载到您的 View 层次结构中。
要使其可见,您应该将其添加为 subview 。在 viewDidLoad
的 MyViewController.m
中,在 [self loadSocialSharingButton];
[self.view addSubview:socialButtons.buttonContainer];
希望对您有所帮助!
关于ios - 自定义 UIView 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30364452/