JXSegmentedDotCell.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // JXSegmentedDotCell.swift
  3. // JXSegmentedView
  4. //
  5. // Created by jiaxin on 2018/12/28.
  6. // Copyright © 2018 jiaxin. All rights reserved.
  7. //
  8. import UIKit
  9. open class JXSegmentedDotCell: JXSegmentedTitleCell {
  10. open var dotView = UIView()
  11. open override func commonInit() {
  12. super.commonInit()
  13. contentView.addSubview(dotView)
  14. }
  15. open override func layoutSubviews() {
  16. super.layoutSubviews()
  17. guard let myItemModel = itemModel as? JXSegmentedDotItemModel else {
  18. return
  19. }
  20. dotView.center = CGPoint(x: titleLabel.frame.maxX + myItemModel.dotOffset.x, y: titleLabel.frame.minY + myItemModel.dotOffset.y)
  21. }
  22. open override func reloadData(itemModel: JXSegmentedBaseItemModel, selectedType: JXSegmentedViewItemSelectedType) {
  23. super.reloadData(itemModel: itemModel, selectedType: selectedType )
  24. guard let myItemModel = itemModel as? JXSegmentedDotItemModel else {
  25. return
  26. }
  27. dotView.backgroundColor = myItemModel.dotColor
  28. dotView.bounds = CGRect(x: 0, y: 0, width: myItemModel.dotSize.width, height: myItemModel.dotSize.height)
  29. dotView.isHidden = !myItemModel.dotState
  30. dotView.layer.cornerRadius = myItemModel.dotCornerRadius
  31. }
  32. }