I would like to add a button to my UIPageViewController just like the bottom right button of the iOS Weather app.
I would like to know what is most correct and clean way of doing it.
Should I access the PageControl somehow and add a subview with the button I want to add or should I hide the Page Control and add a toolbar at the bottom of the view?
Any simple snippet would be most welcome.
Thank you!
In viewDidLoad, add the button to the UIPageViewController's view.
In viewDidAppear, bring the button to front
```
- (void)viewDidLoad {
[super viewDidLoad];
// Add the button
[self.view addSubview:button];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Bring it to front so it appears in front of the UIPageControl
[self.view bringSubviewToFront:button];
}
```
Related
I tried to make floating button on top of uitableview, I already set uitableview to back and the button is in the front on storyboard but when I run the application the table covering the button. How can I make the button to always on front?
Here is the screenshot:
Try to bring your subviews on top of tableview.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view bringSubviewToFront:yourButton];
}
Set autoresizing mask of your buttons from bottom then check. If buttons are not appearing then add this code to in your viewDidLoad method -
[self.view bringSubViewToFront: btn_Cancel];
[self.view bringSubViewToFront: btn_Delete];
I have one label which I am showing on UINavigationBar using addSubView Property and I am getting like:
But when I am going to secondView Controller, it is looking like:
It appears on Back Button of Second Controller. So how to remove "Status" Label from second UI.
Thank You.
Don't add subviews to the navigation bar. It's not made for that.
I recommend you to read the iOS human interface guidelines and to use a UIBarButtonItem to properly add controls to the navigation bar.
In first View controller -
-(void)viewWillAppear:(BOOL)animated
{
//Add Label on UINavigationBar
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:navLabel];
}
-(void)viewWillDisappear:(BOOL)animated
{
// Remove label from UINavigationBar
[super viewWillDisappear:animated];
[navLabel removeFromSuperview];
}
You should tag your subview and search for it among subviews of navigation bar in your second view controller and then [subview removeFromSuperview].
You shouldn't add subviews to your navigation bar, you can use navigation items to achieve that kind of stuff. You can init a UIBarButtonItem with initWithCustomView: which has that label in it.
I have an scrollview with some buttons on it. When one button is clicked I want it to be on top of the screen so that the button.frame.origin.y is the self.view.frame.origin.y. How do I do this?
You can do this
- (void)buttonPressed:(UIButton*)sender
{
[scrollView setContentOffset:sender.frame.origin animated:YES];
}
Use the - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated method.
To scroll the view to the desired frame when the button is pressed.
For example:
- (void)buttonPressed:(UIButton*)sender
{
[scrollView scrollRectToVisible:desireFrameFromButton];
}
I am trying to build a button that will be floating on top of a ViewController, it should remain in the same position statically while the viewcontroller beneath it can scroll up and down.
I designed my own button class and in the viewdidload of the parent Viewcontroller I am doing this :
- (void)viewDidLoad// this is the parent viewcontroller
{
[super viewDidLoad];
customButton *floatingButton = [[UIButton alloc]initWithFrame:(self.view.frame)];
[floatingButton setLocation:CGPointMake(300, 430)];
[self.view addSubview:floatingButton];
[self.view bringSubviewToFront:floatingButton];
This is not doing it, as in when I run the button doesn't show up, only the view controller.
How can I achieve this?
I don't think that you're initializing your button properly. initWithFrame is a UIView initializer, being called by a regular UIButton. I don't see how you would get anything but an empty view here.
If you have a custom initializer for your custom button you should use
[[CustomButton alloc] myCustomInitializerWithFrame:frame];
Thanks guys, but the error was on my end, I wasn't initializing the frame properly, so the button was there but had a height and width of (0,0).
Suppose i have a uiview in 1 screen and i want to view the same view in fullscreen mode on click of a button.
On click of a button the following function is called.
-(IBAction)fullScreen
{
FullScreenViewController *mv = [[FullScreenViewController alloc] init];
mv.fullview = minimizedView;
//minimizedView is a UIView already created with a specified frame
// fullview is a UIView decalred in FullScreenViewController
[[self navigationController] pushViewController:mv animated:YES];
}
In the FullScreenViewController.m the viewDidLoad function is as follows :
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:fullview];
}
On click of the fullscreen button, the view appears but on click of back button, the minimized view in the previous page dissapears.
Is it wrong to do this?
You dont need to use two views to implement this. In your code, your are navigating from one view to another view. You dont need to do that. Your minimizeView itself having a property "setFrame:" to increase and decrease its frame to resize of that subview in your current view itself. Learn how to resize the UIView.