In this section, we are going to create a UICollectionView that will enable you to select different colors. Start with the code from the end of the Setting up Remodel-AR in UIKit tutorial. A link to the starting project is provided here for your convenience.
Step 1
First, we need to create a source for our colors to pull from. Create a new folder called Model. Inside the folder, create a new file Model.swift and edit its contents as below.
Create a new folder called CollectionView. Inside that folder, create another folder called Cells.
Step 3
Create a new file inside of the Cells folder. For Source, select Cocoa Touch Class. Make it a subclass of UICollectionViewCell, and check the "Also create XIB file" check box. Name it ColorPickerCell.
Step 4
Open ColorPickerCell.swift and update its code using the following.
Open ColorPickerCell.xib and add a UIView and create constraints. Assign the view to the colorView variable in the cell. Change the identifier to ColorPickerCell.
Step 6
Create a new file in the CollectionView folder and name it ColorPickerCollectionView.swift. Edit its contents to match below.
Open Main.storyboard and add a UICollectionView and setup its constraints. Delete the default cell that was created inside of it. Change the UICollectionView class type to ColorPickerCollectionView. Change the flow type to horizontal. Create an IBOutlet connected to the view in ViewController named colorPickerCollectionView.
Step 8
Open ViewController and modify configureView() as below.
Build and run. You should be able to scroll through the list and select different colors. The border should change to indicate which color is selected. Next we'll add a texture picker so we can apply textures to the walls.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com