Last active
March 22, 2025 15:06
-
-
Save jerrypm/3793f7856f089f40484721620ab08f4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
here is stackView as tableView in table cell | |
Created by jeri pm | |
*/ | |
import UIKit | |
class StepThreeTableViewCell: UITableViewCell { | |
@IBOutlet weak var titleTable: UILabel! | |
@IBOutlet weak var subview: UIView! | |
var stackView = UIStackView() | |
let wordLabel = UILabel() | |
let descriptionLabel = UILabel() | |
var groupStackView = [UIStackView]() | |
let dataIn: [String] = ["dataA", "dataB"] | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
titleTable.text = "" | |
setupLabels() | |
setupMultipleDataStack() | |
} | |
func setupLabels() { | |
selectionStyle = .none | |
stackView.axis = .vertical | |
stackView.spacing = 16 | |
stackView.alignment = .fill | |
stackView.distribution = .equalSpacing | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
contentView.addSubview(stackView) | |
wordLabel.translatesAutoresizingMaskIntoConstraints = false | |
wordLabel.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lor" | |
wordLabel.numberOfLines = 0 | |
wordLabel.lineBreakMode = .byWordWrapping | |
stackView.addArrangedSubview(wordLabel) | |
descriptionLabel.translatesAutoresizingMaskIntoConstraints = false | |
descriptionLabel.text = "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." | |
descriptionLabel.numberOfLines = 0 | |
descriptionLabel.lineBreakMode = .byWordWrapping | |
stackView.addArrangedSubview(descriptionLabel) | |
wordLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 30).isActive = true | |
descriptionLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 30).isActive = true | |
stackView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor, constant: 10).isActive = true | |
stackView.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor, constant: 10).isActive = true | |
stackView.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor, constant: 10).isActive = true | |
stackView.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor, constant: 10).isActive = true | |
} | |
private func setupMultipleDataStack() { | |
dataIn.forEach { strdata in | |
let imageIsMe = UIImageView() | |
imageIsMe.image = UIImage(systemName: "photo") | |
imageIsMe.heightAnchor.constraint(equalToConstant: 16).isActive = true | |
imageIsMe.widthAnchor.constraint(equalToConstant: 16).isActive = true | |
imageIsMe.autoresizesSubviews = true | |
imageIsMe.isOpaque = true | |
let labelIsMe = UILabel() | |
labelIsMe.font = UIFont.systemFont(ofSize: 12) | |
labelIsMe.backgroundColor = UIColor.clear | |
labelIsMe.textColor = .darkGray | |
labelIsMe.text = strdata | |
let imageClose = UIImageView() | |
imageClose.image = UIImage(systemName: "xmark.circle.fill") | |
imageClose.heightAnchor.constraint(equalToConstant: 16).isActive = true | |
imageClose.widthAnchor.constraint(equalToConstant: 16).isActive = true | |
imageClose.autoresizesSubviews = true | |
imageClose.tintColor = .darkGray | |
imageClose.isOpaque = true | |
// StackViewParent = .Vertical | |
let isGroupStackView = UIStackView(arrangedSubviews: [imageIsMe, labelIsMe, imageClose]) | |
isGroupStackView.axis = .horizontal | |
isGroupStackView.alignment = .fill | |
isGroupStackView.distribution = .fillProportionally | |
isGroupStackView.spacing = 16 | |
groupStackView.append(isGroupStackView) | |
} | |
for grup in groupStackView { | |
stackView.addArrangedSubview(grup) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment