Skip to main content
iOS App Development5 min read

Creating a settings page in UITableView with dynamic elements inside it

By Krunal Vanwari

Creating a settings page in UITableView with dynamic elements inside it

A settings page is what generally every app will need after some time if it is growing and to make a settings page for an app is very difficult trust me. I still remember when I first got a task of creating a settings page for an app I was confused what should I do I need a sliderView for some settings then I need pickerView for some other settings so making it in one tableView was looking like an impossible task but after some advice from experts I finally created a tableView which had dynamic cells having a different type of elements inside it and they controlled the main settings of my app and I will like to share it in this blog because it is not mine its given by our superior developers to all the growing developers.We will assume we have a video playing app and we need to create a settings VC to control the playing of video like volume level, quality of the video, and speed of the video. So for volume control, we will use UISliderView for quality change we will use UISegmentControl and for speed control, we will use UIPickerView all will be in one tableView and will be able to control the settings of our app so let’s get started.First, we will create a tableView and assign dataSource, and delegate it to the viewController.(Note: we are using a lazy variable as with define and call closure of a variable, so the ‘Self’ is not available without it being lazy)

lazy var tableView:UITableView = {
    let tbl = UITableView()
    tbl.translatesAutoresizingMaskIntoConstraints = false
    tbl.dataSource = self
    tbl.delegate = self
    return tbl
}()

Now we will create a tableViewCell and a label inside it, that will show the name of the setting.

class settingsCell:UITableViewCell {

    let titleLabel: UILabel = {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

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

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

We will now give constraints to our tableView and label that will be inside the initializers.

func initTableView() {
    view.addSubview(tableView)
    tableView.rowHeight = 50
    tableView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
    tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
}
func initTitleLabel() {
    contentView.addSubview(titleLabel)
    titleLabel.heightAnchor.constraint(equalToConstant: 50).isActive = true
    titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
    titleLabel.leadingAnchor.constraint(equalTo:contentView.layoutMarginsGuide.leadingAnchor).isActive = true
}

We have given fix height of 50 for our cell and to the titleLabel but we will make it dynamic just trust me for now.

Now registering the cell from tableView and giving data to dataSource of tableView we will see the cells coming.But now how to make it dynamic! we will see that now.

So to make it dynamic we need to know which type of setting we will show in a particular cell so for that we will create an enum for all possible types of controls we want, in our case, it’s 3.

enum CellType {
    case sliderView
    case segmentController
    case pickerView
}

So to make it dynamic we will create and declare a UIView like this in our cell class

private(set) var settingsView: UIView = UIView()

Now we will create functions to initialize our settings view which are slider, segment, and pickerView but we will not declare them separately we will just declare them to our settingsView variable so there will only be one settingsView at a time.

func initSlider() {
    settingsView = UISlider()
    settingsView.translatesAutoresizingMaskIntoConstraints = false
    contentView.addSubview(settingsView)
    settingsView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,constant: contentView.bounds.width * 0.20).isActive = true
    settingsView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor,constant: -(contentView.bounds.width * 0.20)).isActive = true
    settingsView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor).isActive = true
}

func initSegment() {
    settingsView = UISegmentedControl(items: ["low","medium","high"])
    settingsView.translatesAutoresizingMaskIntoConstraints = false
    contentView.addSubview(settingsView)
    settingsView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,constant: contentView.bounds.width * 0.20).isActive = true
    settingsView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor,constant: -(contentView.bounds.width * 0.20)).isActive = true
    settingsView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor).isActive = true
}

func initPicker() {
    settingsView = UIPickerView()
    settingsView.translatesAutoresizingMaskIntoConstraints = false
    contentView.addSubview(settingsView)
    settingsView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
    settingsView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
    settingsView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor).isActive = true
}

Now declaring a variable of currentType in our cell class (we will use it in cellForRow) and make a function to know which type was selected so according to that we will initialize our cell type

var currentCellType:CellType?

func initTheSettingView() {
    if let type = currentCellType {
        switch type {
            case .sliderView:
                initSlider()
            case .segmentController:
                initSegment()
            case .pickerView:
                initPicker()
        }
    }
}

So now our views are being created dynamically according to the type we provide in cellForRow so for that, we will make some variables that will keep our data type of settings as our settings will not change dynamically (still we can do that but that topic is for another day).

let settingsName = ["Volume Level","Video playback quality","playback speed"]
let settingCellType:[settingsCell.CellType] = [.sliderView,.segmentController,.pickerView]

And in our cellForRow we will just take these values from indexPath.row and we are good to go but still, there is a problem how we will expand the cells according to the tap of the user to show the settings selection view for that we need to know the height of the cell component so for that, we will create an array of heights and will append height value of a cell from cellForRow so finally our cellForRow will look something like this

var heights:[CGFloat] = []

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell") as! settingsCell
    let name = settingsName[indexPath.row]
    cell.titleLabel.text = name
    cell.currentCellType = settingCellType[indexPath.row]
    cell.initTitleLabel()
    heights.append(cell.settingsView.bounds.height + 50)
    return cell
}

Now we will implement two more methods didSelectRow and height for row and a variable for tracking whether if the cell has expanded or not and according to that in heightForRow we will give height to our cells here is how to do that

var expandedCells:[Int] = []

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let indx = expandedCells.firstIndex(of: indexPath.row){
        expandedCells.remove(at: indx)
    } else {
        expandedCells.append(indexPath.row)
    }
    tableView.beginUpdates()
    tableView.endUpdates()
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if !expandedCells.contains(indexPath.row) {
        return 50
    } else {
        return heights[indexPath.row]
    }
}

So finally this is what we get by implementing this

Blogs

Field notes on shipping software, design, and everything in between.

AI SDK Laravel - library (1)
Web DevelopmentJul 3, 2026

Laravel AI SDK : A Complete Overview of Building AI Features in PHP

Laravel AI is Laravel’s official, first-party package for building AI features into PHP applications. Instead of pulling in…

Playwright MCP
Web DevelopmentJun 2, 2026

How I Audited and Fixed My Next.js Mobile UI in Minutes Using Playwright MCP

Every developer knows the tedious dance of mobile UI auditing. You deploy your site, open Chrome DevTools, toggle…

agile team management thumbnail
StoriesJul 19, 2023

Agile Team Management Unleashed: Insights from Top 5 Management Books for Small IT Agencies

Welcome to our blog, where we embark on a journey to unlock the secrets of maintaining a small…

Ways to create Effective UI/UX Design Portfolio
UI/UXDec 15, 2022

Ways to create Effective UI/UX Design Portfolio

In an industry where education and experience are not necessarily requirements for a dream position, a UX design…

5 Prototyping Tools for UI/UX Designers
UI/UXSep 12, 2022

5 Prototyping Tools for UI/UX Designers

It may sound cliche, but it’s also true that prototyping plays an important role in communicating how the…

Dark UI Design : Best Practices
UI/UXAug 25, 2022

Dark UI Design : Best Practices

Dark theme was introduced with IOS 13 in September 2019 followed by Android 10(Q) in May 2020 after…

What is viewBinding in Android and How we can use it?
Android App DevelopmentAug 24, 2022

What is viewBinding in Android and How we can use it?

Till now when we want to connect an XML element to a java or kotlin file we always…

5 Figma Plugins that can be used to create Good User Interface
UI/UXAug 24, 2022

5 Figma Plugins that can be used to create Good User Interface

After the launch in 2016, Figma has grown to become one of the leading UI design tools on…

MySQL Tips & Tricks : Functions
Web DevelopmentAug 24, 2022

MySQL Tips & Tricks : Functions

In our previous article on MySQL, we covered Triggers. In this article we are covering another important feature…

Free consultation to scope your
creative projects

Book demo

FAQ

Ask AI to summarize QuriousClick
Have a project in mind?Tell us what you're planning and we'll help you shape the scope, timeline and next steps.
Book a discovery call
  • QuriousClick is a design and development studio. Since 2014 our in-house team has designed, built and supported websites, web and mobile apps, brands and AI products for 100+ customers worldwide.