Don_Mag

Untitled

Aug 30th, 2019
234
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. class MessageCell : UITableViewCell {
  4.     required init?(coder aDecoder: NSCoder) {
  5.         fatalError("init(coder:) has not been implemented")
  6.     }
  7.    
  8.     let label = UILabel()
  9.    
  10.     override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  11.         super.init(style: style, reuseIdentifier: reuseIdentifier)
  12.        
  13.         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."
  14.         label.textAlignment = .right
  15.         label.lineBreakMode = .byWordWrapping
  16.         label.numberOfLines = 0
  17.         label.translatesAutoresizingMaskIntoConstraints = false
  18.        
  19.         backgroundColor = .clear
  20.        
  21.         contentView.addSubview(label)
  22.  
  23.         NSLayoutConstraint.activate([
  24.             // constrain label top to contentView top (use contentView margins)
  25.             label.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor),
  26.             // constrain label bottom to contentView bottom (use contentView margins)
  27.             label.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor),
  28.             // constrain label trailing to contentView trailing (use contentView margins)
  29.             label.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
  30.             // constrain label width to 80% of contentView width (use contentView margins)
  31.             label.widthAnchor.constraint(equalTo: contentView.layoutMarginsGuide.widthAnchor, multiplier: 0.8),
  32.             ])
  33.  
  34.     }
  35. }
RAW Paste Data