JCGroupMemberCell.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // JCGroupMemberCell.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/5/10.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. import JMessage
  10. class JCGroupMemberCell: UICollectionViewCell {
  11. var avator: UIImage? {
  12. get {
  13. return avatorView.image
  14. }
  15. set {
  16. nickname.text = ""
  17. avatorView.image = newValue
  18. }
  19. }
  20. public override init(frame: CGRect) {
  21. super.init(frame: frame)
  22. _init()
  23. }
  24. public required init?(coder aDecoder: NSCoder) {
  25. super.init(coder: aDecoder)
  26. _init()
  27. }
  28. private var avatorView: UIImageView = UIImageView()
  29. private var nickname: UILabel = UILabel()
  30. private lazy var userDefaultIcon = UIImage.loadImage("com_icon_user_50")
  31. private func _init() {
  32. nickname.font = UIFont.systemFont(ofSize: 12)
  33. nickname.textAlignment = .center
  34. addSubview(avatorView)
  35. addSubview(nickname)
  36. addConstraint(_JCLayoutConstraintMake(avatorView, .centerY, .equal, contentView, .centerY, -10))
  37. addConstraint(_JCLayoutConstraintMake(avatorView, .width, .equal, nil, .notAnAttribute, 50))
  38. addConstraint(_JCLayoutConstraintMake(avatorView, .height, .equal, nil, .notAnAttribute, 50))
  39. addConstraint(_JCLayoutConstraintMake(avatorView, .centerX, .equal, contentView, .centerX))
  40. addConstraint(_JCLayoutConstraintMake(nickname, .centerX, .equal, contentView, .centerX))
  41. addConstraint(_JCLayoutConstraintMake(nickname, .width, .equal, nil, .notAnAttribute, 50))
  42. addConstraint(_JCLayoutConstraintMake(nickname, .height, .equal, nil, .notAnAttribute, 15))
  43. addConstraint(_JCLayoutConstraintMake(nickname, .top, .equal, avatorView, .bottom, 5))
  44. }
  45. func bindDate(user: JMSGUser) {
  46. nickname.text = user.displayName()
  47. let urlstr = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":user.username as AnyObject])
  48. let url = URL(string: urlstr!)
  49. let bound = self.avatorView.bounds
  50. if bound.width <= 0 || bound.height <= 0 {
  51. self.avatorView.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
  52. }
  53. self.avatorView.hnk_setImageFromURL(url!)
  54. // user.thumbAvatarData { (data, id, error) in
  55. // if let data = data {
  56. // let image = UIImage(data: data)
  57. // self.avatorView.image = image
  58. // } else {
  59. // self.avatorView.image = self.userDefaultIcon
  60. // }
  61. // }
  62. }
  63. }