CustomGroupDetailImageCell.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // CustomGroupDetailImageCell.swift
  3. // DKImagePickerController
  4. //
  5. // Created by ZhangAo on 03/01/2017.
  6. // Copyright © 2017 ZhangAo. All rights reserved.
  7. //
  8. import UIKit
  9. import ThreemaFramework
  10. class CustomGroupDetailImageCell: DKAssetGroupDetailBaseCell {
  11. class override func cellReuseIdentifier() -> String {
  12. return "CustomGroupDetailImageCell"
  13. }
  14. override init(frame: CGRect) {
  15. super.init(frame: frame)
  16. self.thumbnailImageView.frame = self.bounds
  17. self.thumbnailImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  18. self.contentView.addSubview(self.thumbnailImageView)
  19. self.checkView.frame = self.bounds
  20. self.checkView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  21. self.checkView.checkImageView.tintColor = nil
  22. self.checkView.checkLabel.font = UIFont.boldSystemFont(ofSize: 14)
  23. self.checkView.checkLabel.textColor = UIColor.white
  24. self.contentView.addSubview(self.checkView)
  25. self.isAccessibilityElement = true
  26. if #available(iOS 11.0, *) {
  27. self.thumbnailImageView.accessibilityIgnoresInvertColors = true
  28. }
  29. }
  30. required init?(coder aDecoder: NSCoder) {
  31. fatalError("init(coder:) has not been implemented")
  32. }
  33. class DKImageCheckView: UIView {
  34. private class func stretchImgFromMiddle(_ image: UIImage) -> UIImage {
  35. let centerX = image.size.width / 2
  36. let centerY = image.size.height / 2
  37. return image.resizableImage(withCapInsets: UIEdgeInsets(top: centerY, left: centerX, bottom: centerY, right: centerX))
  38. }
  39. internal lazy var checkImageView: UIImageView = {
  40. let imageView = UIImageView(image: CustomGroupDetailImageCell.DKImageCheckView.stretchImgFromMiddle(StyleKit.checkedBackground))
  41. return imageView
  42. }()
  43. internal lazy var checkLabel: UILabel = {
  44. let label = UILabel()
  45. label.textAlignment = .right
  46. return label
  47. }()
  48. override init(frame: CGRect) {
  49. super.init(frame: frame)
  50. self.addSubview(checkImageView)
  51. self.addSubview(checkLabel)
  52. }
  53. required init?(coder aDecoder: NSCoder) {
  54. fatalError("init(coder:) has not been implemented")
  55. }
  56. override func layoutSubviews() {
  57. super.layoutSubviews()
  58. self.checkImageView.frame = self.bounds
  59. self.checkLabel.frame = CGRect(x: 0, y: 5, width: self.bounds.width - 5, height: 20)
  60. }
  61. } /* DKImageCheckView */
  62. override var thumbnailImage: UIImage? {
  63. didSet {
  64. self.thumbnailImageView.image = self.thumbnailImage
  65. }
  66. }
  67. override var index: Int {
  68. didSet {
  69. self.checkView.checkLabel.text = "\(self.index + 1)"
  70. }
  71. }
  72. fileprivate lazy var thumbnailImageView: UIImageView = {
  73. let thumbnailImageView = UIImageView()
  74. thumbnailImageView.contentMode = .scaleAspectFill
  75. thumbnailImageView.clipsToBounds = true
  76. return thumbnailImageView
  77. }()
  78. internal let checkView = DKImageCheckView()
  79. override var isSelected: Bool {
  80. didSet {
  81. checkView.isHidden = !super.isSelected
  82. }
  83. }
  84. } /* DKAssetGroupDetailCell */