JCMyInfoCell.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // JCMyInfoCell.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/3/30.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. class JCMyInfoCell: JCTableViewCell {
  10. var icon: UIImage? {
  11. get {
  12. return iconView.image
  13. }
  14. set {
  15. iconView.image = newValue
  16. }
  17. }
  18. var title: String? {
  19. get {
  20. return titleLabel.text
  21. }
  22. set {
  23. titleLabel.text = newValue
  24. }
  25. }
  26. var detail: String? {
  27. get {
  28. return detailLabel.text
  29. }
  30. set {
  31. detailLabel.text = newValue
  32. }
  33. }
  34. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  35. super.init(style: style, reuseIdentifier: reuseIdentifier)
  36. _init()
  37. }
  38. required init?(coder aDecoder: NSCoder) {
  39. super.init(coder: aDecoder)
  40. _init()
  41. }
  42. override func awakeFromNib() {
  43. super.awakeFromNib()
  44. _init()
  45. }
  46. private lazy var iconView: UIImageView = UIImageView()
  47. private lazy var titleLabel: UILabel = {
  48. let titleLabel = UILabel()
  49. titleLabel.font = UIFont.systemFont(ofSize: 16)
  50. titleLabel.backgroundColor = .white
  51. titleLabel.layer.masksToBounds = true
  52. return titleLabel
  53. }()
  54. private lazy var detailLabel: UILabel = {
  55. let detailLabel = UILabel()
  56. detailLabel.textAlignment = .right
  57. detailLabel.font = UIFont.systemFont(ofSize: 14)
  58. detailLabel.textColor = UIColor(netHex: 0x999999)
  59. detailLabel.backgroundColor = .white
  60. detailLabel.layer.masksToBounds = true
  61. return detailLabel
  62. }()
  63. private func _init() {
  64. addSubview(iconView)
  65. addSubview(titleLabel)
  66. addSubview(detailLabel)
  67. addConstraint(_JCLayoutConstraintMake(iconView, .top, .equal, contentView, .top, 13.5))
  68. addConstraint(_JCLayoutConstraintMake(iconView, .left, .equal, contentView, .left, 15))
  69. addConstraint(_JCLayoutConstraintMake(iconView, .width, .equal, nil, .notAnAttribute, 18))
  70. addConstraint(_JCLayoutConstraintMake(iconView, .height, .equal, nil, .notAnAttribute, 18))
  71. addConstraint(_JCLayoutConstraintMake(titleLabel, .centerY, .equal, contentView, .centerY))
  72. addConstraint(_JCLayoutConstraintMake(titleLabel, .left, .equal, iconView, .right, 10))
  73. addConstraint(_JCLayoutConstraintMake(titleLabel, .width, .equal, nil, .notAnAttribute, 100))
  74. addConstraint(_JCLayoutConstraintMake(titleLabel, .height, .equal, nil, .notAnAttribute, 22.5))
  75. addConstraint(_JCLayoutConstraintMake(detailLabel, .centerY, .equal, contentView, .centerY))
  76. addConstraint(_JCLayoutConstraintMake(detailLabel, .left, .equal, titleLabel, .right))
  77. addConstraint(_JCLayoutConstraintMake(detailLabel, .right, .equal, contentView, .right))
  78. addConstraint(_JCLayoutConstraintMake(detailLabel, .height, .equal, contentView, .height))
  79. }
  80. }