以编程方式添加UIButton将不会显示

Zac*_*yne 3 objective-c uibutton uiscrollview ios8

我目前正在iOS 8 application为iOS 8发布的应用程序商店做好准备,我显然不能显示很多代码,因为我保持项目非常安静但是我正在创建一个带有滚动视图的视图控制器和许多对象为用户创建一个配置文件,但是我正在尝试向所有用户添加一个按钮以将项目添加到他们的配置文件中,并且该按钮不会被添加到滚动视图...是否有一个不成文的规则与UIButtons和UIScrollViewS'

下面是我用来创建按钮的代码

UIButton *addProject = [[UIButton alloc] initWithFrame:CGRectMake(210, 285, 100, 18)];
[addProject setTitle:@"Show View" forState:UIControlStateNormal];
[addProject addTarget:self action:@selector(addProjectPressed:) forControlEvents:UIControlEventTouchUpInside];
[_scrollView addSubview:addProject];
Run Code Online (Sandbox Code Playgroud)

有什么我需要以不同的方式将它添加到滚动视图中吗?

编辑1: _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 699);

编辑2:此外,滚动视图在故事板中创建并具有框架,0, 64, 320, 455但内容大小如上所示具有更大的高度

Vin*_*ngh 9

试试这个;

UIButton *addProject = [UIButton buttonWithType: UIButtonTypeRoundedRect];
addProject.frame = CGRectMake(210, 285, 100, 18);
[addProject setTitle:@"Show View" forState:UIControlStateNormal];
[addProject addTarget:self action:@selector(addProjectPressed:) forControlEvents:UIControlEventTouchUpInside];
[_scrollView addSubview:addProject];
Run Code Online (Sandbox Code Playgroud)

尝试添加此行;

addProject.backgroundColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)

由于相同的背景颜色,它可能不会出现.