Create a photo booth from library to pick images - ios

I'm new to xcode. I am trying to create a photo booth which appears at the bottom (as the one in the image) so that i can make multiple selections and view the result at the top. Any knows how this can be achieved?

You have to implement UICollectionView for photo booth.
For UI design follow the given steps,
Create a UIViewController
Add UICollectionView on UIViewController
Set constraint according to your UI design
Set UICollectionCell height and width same and set mini spacing whatever you want in For cells 5 and For lines 5
and for programming part,
Take data from where you get json parsing or your static data.
Store in one array and reload UICollectionView
Then assign data to your UICollectionView using their delegates and datasource methods.

Related

Should I choose ViewController or TableViewController?

New to Swift. I am trying to write a recipe-sharing app for fun. One of the features is to let users create a new recipe. On this page, users should be able to give an intro to the recipe to be created, upload an image THEN add a LIST of ingredients dynamically (as we have no idea how many ingredients in total beforehand).
I have created a UIViewController, which includes a UIViewTable, an image view and a "add another ingredient" button. I have created a class for the ingredient. And when the "add" button is pressed, a new "Ingredient" cell will be added to the table. However, I found that adjusting the UIViewTable height dynamically is quite hard.
I want my table to adjust its height according to the number of cells (rows). I haven't found much useful info online.
Or maybe I should've not even used this structure. Instead, just use UITableController (The entire page is a table)? But I got confused that some of the elements (image view, submit a recipe button, recipe-intro textfield etc) will be only created once. Why do I bother making them as prototype cells and add them to my view programmatically?
Thanks in advance!
First of all, welcome to Swift!
You put a few questions together, I will try to answer them one by one. Let's start with the simple stuff.
Don't try to change the height of UITableView based on the number of items. If you want to achieve similar functionality, take a look at UIStackView. Set fixed size for the tableView, ideally with constraints using auto layout.
UITableView is supposed to fill specified space and scroll items inside or show cell on top if there are not enough cells to cover all space.
UITableView is highly optimized to scroll over huge amount of cells as the cells are reused on the background. If you are new to the iOS world, take a look at this function https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse it can save you hours of debugging (I have been there)
UITableView vs UITableController
UITableController can save you a few lines of code, but using UITableView inside of UIViewController can give you more freedom and save you refactoring if your app is likely to change in the future. There is no specific advantage of UITableController
If you want to provide the extra elements (image view, submit button, text field etc), you can use several methods and this is where the UIViewController with your own UITableView comes in handy.
You can put some buttons, like a plus icon or "Done" button into the navigation bar, as the native Calendar app does.
You can put the static content (intro text field, image view) above the table view (visible always). Use constraints to place the static content on the viewController.view and constraint the table view under your static content. The table view will take less space on the view keeping the space for your content.
Insert your static content as a table view header (will scroll out with the content). Search "HeaderView" here on stack overflow to see how to achieve that.
Place your content over the tableView. If your button is small (rounded), you can place it over the tableView, eg. Twitter uses this for a new tween button.
Hope this answer your questions. Cheers!

How to create a complex scrolling view in iOS similar to yelp?

Yelp has this View show up when you click on a specific restaurant or some event:
In the picture above there is the Cascal label, then Write a Review button, then three buttons (Photo or Video, Check in, Bookmark) all in a row, then a map, and some cells underneath (Directions, Call, Explore the menu, etc.).
How can you make a complex scrolling view similar to this (do you have to use a collection view or table view?)? Since in both a tableview and collectionview you are reusing the same cells again and again (with the same layout) so it is difficult to create a view with so many heterogeneous elements like in the picture above.
Use a table view and a bunch of different cell classes each with their unique design (XIB or Storyboard) and height.
Select the cell class and height depending on index path and let table view delegate methods return accordingly.
Very basic stuff actually.
You only reuse cell classes if you need to. In the Yelp example the Directions, Call, Explore the Menu and More Info cells may have used the same design because the layout seems to be identical, only the image and text differs.

how to create multiple button in ios?

I have create one custom cell and I want to create multiple button in that cell in ios. I have created multiple buttons in cell but I have problem on selection.I want to select first button by default.Check image for better understanding
Image
I would make this a collectionView that allows single selection. This is because you are representing sizes/dimensions and they come in notoriously different and arbitrary scales (0-14, XS-XL, 28-44, etc). If you make a it a collection view it very easy to handle arbitrary size scales by modifying the collection view datasource methods. If you make this a fixed set of buttons and someone comes along and changes the size scale, you have a problem.

How to design a ViewController with complex TableView

Imagine this scenario:
I've 10 different and custom UITableViewCell: one with a textfield,
one with a button, one with some labels, one with a textview, one
with an imageView and so on.
I've a ViewController with a tableView where I wanna display these cells.
The number of cell displayed can vary based on some conditions (and also the height, the background color and other parameters)
The user can interact with these cells
What is the best way to design this in respect of the MVC and maintain the ViewController lightweight and maintainable as possible?
How to take advantage of Swift language in doing this?
Is there any famous and consolidate design pattern to apply?
i will try to share some of my experience:
Create separate custom UITableViewCelll as per requirement like : textfield, textview, imageview, label etc. this class must not dependent on data calculation it is only for cosmetics UI. that means there must not be any method like updateCellWithData:(someDATAObj). This logic must go in some cetegory as discussed below.
Register separate custom UITableViewCelll with your tableview.
Create separate class (NSObject) as datasource and delegate for your UITableView.
Use category to populate data in your custom UITableView Cell. some thing like updateCellWithData:(someDATAObj).
Use constant file for your constants like height for tableView Cell, reuse identifier names, notification name.
try with some code atleast, then we can help you with best.

View Polymorphism in iOS

What is the correct way to do view polymorphism in iOS? For example, I have custom table view cells that need to contain either a custom BarChartView or LineChartView. I decide at run time whether the table view cell will hold a line or bar chart. Ideally, I want to only create one xib file for the table view cell that layouts the bar/line chart view with other things (like labels for chart title, etc), and I can decide at run time whether the view that holds the chart is going to become a BarChartView or LineChartView. Is it possible to set the morphing view in the xib file in Interface Builder to be one of the superclasses, for example UIView, and then later programmatically decide which subclass it should become? If so, what's the best way to do that?
Step 1. Make two view in custom cell xib file for BarChartView or LineChartView.(Both in single xib only)
Step 2.Write conditions in cellFoRowAtIndexPath to get either BarChartView or LineChartView view to Show.
Note:- Now,there might be condition ,weather to show/hide tableview ,depends on you.
But once tableview need to be displayed, use Step 1 & 2 to dynamic view loading.
maybe have a custom view inside contentView of your cell and just add barChartView or lineChartView to that view. So, even If you need to support more Chart types that'll be doable

Resources