I am currently in process of making a registration form on my app in Swift 3 / xcode and I first have 3 text fields showing with a continue button underneath, I want it so the user presses the continue button and the current stackview slides out of view and a new one slides in (similar to a segue with the storyboards
This will show first and then they press continue:
Then this stack view will show:
Could somebody please point me in the right direction of how to do this?
Thank you.
For your case, I'm not pretty sure of what is the purpose of using a stackView. I suggest to use UICollectionView (horizontal) instead (UIStackView does not scroll which is inappropriate for what are you trying to achieve), especially that the two views should be the same cell in your case. All you have to do is to check what's the current indexPath.row for determining what cell's components should look/behave.
Also, You can add target to the button to let the collectionView scrolls to the next cell if it's the first row, for the second row it should -for example- submit the form.
Hope it helped.
#Chad, if you want to use scrollable and easy solution you could try ScrollableStackView library. Here is the github page :
https://github.com/gurhub/ScrollableStackView
Here is some sample codes :
Swift
import ScrollableStackView
var scrollable = ScrollableStackView(frame: view.frame)
view.addSubview(scrollable)
// add your views with
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 55))
rectangle.backgroundColor = UIColor.blue
scrollable.stackView.addArrangedSubview(rectangle)
// ...
Objective-C
#import ScrollableStackView
ScrollableStackView *scrollable = [[ScrollableStackView alloc] initWithFrame:self.view.frame];
scrollable.stackView.distribution = UIStackViewDistributionFillProportionally;
scrollable.stackView.alignment = UIStackViewAlignmentCenter;
scrollable.stackView.axis = UILayoutConstraintAxisVertical;
[self.view addSubview:scrollable];
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 55)];
[rectangle setBackgroundColor:[UIColor blueColor]];
// add your views with
[scrollable.stackView addArrangedSubview:rectangle];
// ...
Hope it helps.
Related
I'm working on a app, in which I need to keep a navigation bar.
when I write any title on the bar, the time and the title kinda get very close to each other. I wanted to increase the height of the bar, so it can get some breathing room.
select your ViewController --> select your Navigation Item --> Prompt --> Add space it increase the height of **Navigation bar**
Check Image here :
Programatically
Add this in viewWillAppear or viewDidAppear method
Objective-C
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, self.view.frame.size.width,80.0)];
Swift
self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 80.0)
Swift-3
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 80.0)
iOS 11
objective C
for (UIView *subview in self.navigationController.navigationBar.subviews) {
if ([NSStringFromClass([subview class]) containsString:#"BarBackground"]) {
CGRect subViewFrame = subview.frame;
// subViewFrame.origin.y = -20;
subViewFrame.size.height = 100;
[subview setFrame: subViewFrame];
}
}
swift
for subview in (self.navigationController?.navigationBar.subviews)! {
if NSStringFromClass(subview.classForCoder).contains("BarBackground") {
var subViewFrame: CGRect = subview.frame
// subViewFrame.origin.y = -20;
subViewFrame.size.height = 100
subview.frame = subViewFrame
}
}
simply add this line to your viewController
navigationController?.additionalSafeAreaInsets.top = 30
// where 30 is the extra space, add as per your need.
Apple proposes not to resize navigationBar itself, but remove shadow from bar and add custom view under your navigationBar. This can work for most cases. Check Apple's samples.
Add the following extension to your project:
import UIKit
extension UINavigationBar {
override open func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: UIScreen.main.bounds.size.width, height: 80.0)
}
}
Please refer the apple recommended approach for extended navigation bar here,
https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html
THIS SOLUTION NO LONGER WORKS IN Xcode 8.x.x and later!
you can also increase height without creating the custom navigation follow the following steps
Step 1 Selecte Navigation bar in Storyboard or XIB
Step 2 Copy ObjectID from Identity Inspector
Step 3 Open Storyboard/XIB as Source Code
Step 4 Find ObjectID in Source Code past ObjectID in search
Step 5 Edit height! thats all
I hope this will help you
Add this in viewWillAppear method
CGFloat height = 80;
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0,
self.view.frame.size.width,height)];
if it increase first and shrinks to original height then add this code in viewDidAppear method
We need to change the height of the navigation bar for each time the view show.So put the code on viewWillAppear
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 80)
}
we can set the width as the width of the view and change the height as we wish.
You can't change the height of the default NavigationBar if I'm not wrong.
Although, you can create a custom NavigationBar and add a custom height to it.
navigationController?.additionalSafeAreaInsets.top = 25
Add this to viewDidLoad. it will definitely work. Successfully worked in Xcode 12-version
[self.navigationController.navigationBar setPrefersLargeTitles:YES];
is going to Increase the Navigation bar height Programmatically
I have the code below in my viewcontroller.m:
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectMake(0, 0, 10, 25)];
self.view = panoView_;
[panoView_ moveNearCoordinate:CLLocationCoordinate2DMake(-33.732, 150.312)];
I want to create a little space at the bottom of the view to place a button in the storyboard but this isn't working as the map (street view) takes up the entire screen. Any advice?
If you want the button to appear below the map then use 2 views.one view (panoViewContainer) contains a panoView and second view (mainView - which is self.view) contains panoViewContainer and a button below panoViewContainer.
// Place panoViewContainer in mainView by keeping space for button at bottom,
self.panoViewContainer.frame = CGRectMake(0, 0, width, (height - spaceForButton));
[self.mainView addSubview:self.panoViewContainer];
self.panoViewContainer = panoView_;
// Place a button in mainView, below panoViewContainer.
[self.mainView addSubview:button];
Hello i need to add custom cell accessoryView in my app.
Here is my code for custom cellAccessorView.
self.viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
self.lblDay.text = #"Monday";
[self.viewOfAccessory addSubview:self.lblDay];
cell.accessoryView = self.viewOfAccessory;
However it showing only in first row. Not in every row of tableView.
I want to do like following pic.
How can i do it?
A view can only be added in one place. You are using the self.viewOfAccessory property to define what you want shown and then trying to add it to all of your cells. However, self.viewOfAccessory will only show up in one place. If you add it somewhere else (i.e. another row) it will just be moved. You need to be creating separate views and adding them to each cell.
I believe the problem might be because you're calling elements as part of "self" and then adding them again in "self" (which should be the tableViewController), try this:
UIView* viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
//Get the text from lblDay label, check if the "self." is necessary
self.lblDay.text = #"Monday"; //Not sure about this line since I don't have the whole code
[viewOfAccessory addSubview: lblDay];
cell.accessoryView = viewOfAccessory;
This question already has answers here:
How to put buttons over UITableView which won't scroll with table in iOS
(10 answers)
Closed 9 years ago.
Is it possible to add a small floating 'settings' button or image-button over a table view? I have buttons on a navigation bar up top, and i dont want to crowd that or remove any
This is possible by adding it to the main window as a subview. Another option and my preferred method: Have a main wrapper view, the table view can be added to that wrapper view as a subview, then add your button as another subview inside of the wrapper view and voila
Perhaps adding a toolbar with buttons at the bottom would be a better approach?
To use this method, you should inherit UIViewController and add tableview in it
(1)add button to self.tableview in viewDidLoad()
button.frame = CGRectMake(0, 0, 50, 50);
[self.tableview addsubview:button];
[self.tableview bringSubviewToFront:button];
(2)set tableview delegate
self.tableview.delegate = self;
(3) add and update button location to self.tableview in scrollViewDidScroll delegate
button.frame = CGRectMake(0, 0, 50, 50);
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
voila~
I am creating an iPad app using the master-detail template available in Xcode 4.3. My master tableview is acting as a navigation menu for the detail view and the menu items will be fixed. So I basically don't exactly need the scrolling view, thus I have turned it off.
self.tableView.scrollEnabled = NO;
Now I have a requirement to display a footer like cell aligned at the bottom of master menu just like in Twitter iPad app. The cell should appear at the bottom in landscape as well as portrait modes. Can somebody give me some hints regarding how to implement this?
I read on some blogs about using a UIView and setting it to UITableView.tableFooterView, something like this...
// I'll have to do calculations of frame height/x/y for both orientations
// to make the view appear at bottom - IS THERE A SIMPLER WAY???
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 944, self.tableView.frame.size.width, 60)];
UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
logo.text = #"This is the Footer.";
[footerView addSubview:logo];
self.tableView.tableFooterView = footerView;
After looking at the app, I don't think the "footer" is part of the table. It looks more like a small view under the table. So the table is set up so it will stretch vertically but it's height is locked above the bottom view. Maybe it would be better to use a UIViewController and a UIView for you Master View instead of a UITableViewController. Then put your UITableView in the UIView and put your footer below it. Then configure the UIViewController to work with the UITableView as it did before.
Hope this helps.