I hope this helps-- The whole code for the table cell I am making:
import UIKit
class PostsTableViewCell: UITableViewCell {
static let reuseIdentifier: String = "PostsTableViewCell"
private let profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
imageView.layer.masksToBounds = true
imageView.layer.cornerRadius = 10
imageView.clipsToBounds = true
let config = UIImage.SymbolConfiguration(pointSize: 35)
imageView.image = UIImage(systemName: "person.crop.circle.fill", withConfiguration: config)
//imageView.backgroundColor = .white
return imageView
}()
private let profileNameLabel: UILabel = {
let label = UILabel()
label.text = "Testing User"
label.font = .systemFont(ofSize: 16, weight: .bold)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private let userHandel: UILabel = {
let label = UILabel()
label.text = "@Test"
label.font = .systemFont(ofSize: 12, weight: .light)
label.textColor = .systemBlue
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private let postTextLabel: UILabel = {
let label = UILabel()
label.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 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."
label.numberOfLines = 0
label.font = .systemFont(ofSize: 14, weight: .regular)
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(profileImageView)
contentView.addSubview(profileNameLabel)
contentView.addSubview(userHandel)
profileImageView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
let innerPostStackView = UIStackView(arrangedSubviews: [profileNameLabel, userHandel, postTextLabel])
innerPostStackView.axis = .vertical
let postStackView = UIStackView(arrangedSubviews: [profileImageView, innerPostStackView])
postStackView.translatesAutoresizingMaskIntoConstraints = false
postStackView.alignment = .center
postStackView.spacing = 10
contentView.addSubview(postStackView)
NSLayoutConstraint.activate([
postStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),
postStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15),
postStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10),
postTextLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -15)
])
}
required init(coder: NSCoder) {
fatalError("Post failed to load")
}
}
I tried to the paste and match thing But I Don't how that works. I just used the code block after pasting it.
Best,
Imran