OOMeetingRoomDeviceListView.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // OOMeetingRoomDeviceListView.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/18.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOMeetingRoomDeviceListView: UIView {
  10. //设备名字数组
  11. //传入的设备名字列表,以#分隔
  12. var deviceNameList:String? {
  13. didSet {
  14. guard let devices = deviceNameList else {
  15. return
  16. }
  17. self.subviews.forEach { (view) in
  18. view.removeFromSuperview()
  19. }
  20. devices.split(separator: "#").forEach { (device) in
  21. let dView = UIImageView(image: UIImage(named: "icon_meeting_\(device)"))
  22. self.addSubview(dView)
  23. }
  24. self.layoutIfNeeded()
  25. }
  26. }
  27. private var spaceWidth:CGFloat = 5
  28. override init(frame: CGRect) {
  29. super.init(frame: frame)
  30. }
  31. required init?(coder aDecoder: NSCoder) {
  32. super.init(coder: aDecoder)
  33. }
  34. override func layoutSubviews() {
  35. super.layoutSubviews()
  36. var x:CGFloat = 0
  37. let y:CGFloat = 0
  38. let width:CGFloat = 20
  39. let height:CGFloat = 20
  40. self.subviews.forEach { (view) in
  41. if view.isKind(of: UIImageView.self) {
  42. view.frame = CGRect(x: x + spaceWidth, y: y, width: width, height: height)
  43. x += (width + spaceWidth)
  44. }
  45. }
  46. }
  47. }