Let say I have a UIScrollView and a button, how can I set the button floating above the UIScrollView or Window? (or stick the button in the center of the screen no matter how it will scroll).
Any suggestion will be appreciated.
Assuming you are working with a storyboard, simply add the button above the scroll view and not inside it. You might also want to set your constraints of the button to the superview of the scrollview and the button to make it completely independent of the scroll view.
so it will be something like this:
At the ViewDidLoad Method:
// Adding ScrollView
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
// Adding Button
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With