Convert to List

Convert the List design to iOS/Android code.

List to Swift/Android code

If you need to display scrolling elements dynamically, you should check if they are lists or grids. You can find how to understand the difference here. If you have decided that you want to create lists, this is right please to read.

An example of a list is below. In the image, the cell prototype repeats itself with different data inside.

Lists are called different names in iOS and Android. They are explained below with the code and details.

Generated code for iOS/Android and Details

TableView

Lists are called inTableView Swift language. With TableView, you can view a group that aligns all children in a single direction. InTableView, no matter how wide they are, the vertical list has only one child per row, and your list will only be the one-row height(Height of the tallest child + padding).

CellPrototypewraps a layout and will often be the container used in a layout for each item within a TableView. Let's check the generated code.

TableView is added to the page's View Controller file.

ListPageViewController.swift
import UIKit

class ListPageViewController: UIViewController {

//Connection from an Interface Builder to a UI component
@IBOutlet private weak var explorePostsTableView: UITableView!

	override func viewDidLoad() {
		super.viewDidLoad()
		setupViews()
	}
}

extension ListPageViewController {
	private func setupViews() {
	
		//TableView properties
		self.explorePostsTableView.rowHeight = UITableView.automaticDimension
		self.explorePostsTableView.estimatedRowHeight = 30
		self.explorePostsTableView.dataSource = self	

	}
	
}		

// MARK: - Table View DataSource

extension ListPageViewController: UITableViewDataSource {
	func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
		return 1
	}

	func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
		let cell = tableView.dequeueReusableCell(withIdentifier: "ExplorePostTableViewCell") as! ExplorePostTableViewCell
		return cell
	}
}

The Cell is added as a separate file.

ExplorePostsTableViewCell.swift

import UIKit
import SnapKit

class ExplorePost: UITableViewCell {
	
	// MARK: - Properties
	@IBOutlet private weak var photoImageView2: UIImageView!
	@IBOutlet private weak var rosieDelLabel: UILabel!
	@IBOutlet private weak var likesLabel: UILabel!
	@IBOutlet private weak var heartLikedImageView: UIImageView!

	override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
		super.init(style: style, reuseIdentifier: reuseIdentifier)
		self.setupViews()
	}

	required init?(coder aDecoder: NSCoder) {
		super.init(coder: aDecoder)
	}

	func setupViews() {
		
		rosieDelLabel.text = NSLocalizedString("rosie.del", comment: "")
		rosieDelLabel.textColor = UIColor.porpoise
		rosieDelLabel.numberOfLines = 0
		rosieDelLabel.font = UIFont.textStyle2
		rosieDelLabel.textAlignment = .left

		likesLabel.text = NSLocalizedString(".likes2", comment: "")
		likesLabel.textColor = UIColor.anchor2
		likesLabel.numberOfLines = 0
		likesLabel.font = UIFont.textStyle6
		likesLabel.textAlignment = .right

	}
}

Last updated