ios - UIView 不允许我添加 subview

标签 ios xcode uiview uiviewcontroller addsubview

所以我有一个 View ,在我的 viewcontoller 类中,我尝试使用以下代码添加一个 subview 。

    UIButton *test = [[UIButton alloc]initWithFrame:CGRectMake(30, 100, 100, 100)];
    [self.view addSubView:test];

什么也没发生,没有错误或任何事情。我知道它被调用,因为它位于 viewdidload 方法中。我有一个单独的类,我是 uiview 的子类,这与它有什么关系吗?

最佳答案

UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(30, 100, 100, 100);
[self.view addSubView:test];

关于ios - UIView 不允许我添加 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13983982/

相关文章:

objective-c - 在 UIVew 下的 UIButton 上启用用户交互?

ios - 有没有办法从 RPBroadcastSampleHandler 中优雅地完成广播?

iphone - iAd 横向奇怪的 View 行为

ios - 如何调配 Swift.print(项目 :separator:terminator)

Xcode 6 不显示 iOS 7.1 模拟器

swift - 核心数据,初始化 managedObjectContext

ios - 在 Swift 的警报中使用自定义 View

android - 允许用户在谷歌地图中选择不同的自定义标记

iphone - 视频编辑,例如 Aviary 图像编辑或 Instagram 应用

swift - 呈现的 UIView 的可变高度