假设我有一个UIScrollView和一个按钮,如何将按钮设置为浮动在UIScrollView或窗口上方?(或者无论如何滚动,都将按钮粘贴在屏幕中央。)
非常感谢您的建议。
非常感谢您的建议。
UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)];
scrollview.showsVerticalScrollIndicator=YES;
scrollview.scrollEnabled=YES;
scrollview.userInteractionEnabled=YES;
[self.view addSubview:scrollview];
scrollview.contentSize = CGSizeMake(320,960);//You Can Edit this with your requirement
// 添加按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
scrollView
上,因为您将其添加为scrollview
的子视图。您应该将其作为主视图的子视图添加。[self.view addSubview:button];
- GoGreen