Reputation: 5
I am new to iOS programming. I am working on an app that will ask user to choose options shown in the image. I want to build it programmatically. Can someone help me with that?
Each row has three dot menu option:
Thanks in advance
Upvotes: 1
Views: 3130
Reputation: 41
Try this code for add three dots in UITableViewCell.
func setupCell() {
var menuButton = UIButton()
menuButton = UIButton(type: .system)
menuButton.setImage(UIImage(named: "three_dot_icon"), for: .normal) // Use your three-dot icon
menuButton.addTarget(self, action: #selector(actionMenuButton), for: .touchUpInside)
// Add the menu button to the cell's content view
contentView.addSubview(menuButton)
// Set constraints for the menu button
menuButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
menuButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
menuButton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
menuButton.widthAnchor.constraint(equalToConstant: 30),
menuButton.heightAnchor.constraint(equalToConstant: 30)
])
}
@objc func actionMenuButton() {
print("Menu button tapped")
}
Upvotes: 0
Reputation: 2077
A simple way to do this would be to create a custom UITableViewCell
, and place a button on the right side of the cell with its image as the three-dot menu that you referenced. You can accomplish this by subclassing UITableViewCell
. There are numerous examples of this online.
Upvotes: 0