O2CollectionViewCell.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // O2CollectionViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/6/17.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class O2CollectionViewCell: UICollectionViewCell {
  11. override func awakeFromNib() {
  12. self.backgroundColor = UIColor.white
  13. }
  14. @IBOutlet weak var appIconImageView: UIImageView!
  15. @IBOutlet weak var opIconImageView: UIImageView!
  16. @IBOutlet weak var appTitle: UILabel!
  17. private var nowData:O2App?
  18. override func prepareForReuse() {
  19. super.prepareForReuse()
  20. self.appIconImageView.image = nil
  21. }
  22. // editIcon 0 不编辑 1 选中的应用显示删除icon 2 选中的应用显示已选择的icon 3未选中的应用显示可选择的icon
  23. func setAppData(app: O2App, editIcon: Int) {
  24. self.nowData = app
  25. if editIcon == 0 {
  26. self.opIconImageView.isHidden = true
  27. } else {
  28. if editIcon == 1 {
  29. self.opIconImageView.image = UIImage(named: "icon_jian_1")
  30. } else if editIcon == 2 {
  31. self.opIconImageView.image = UIImage(named: "icon__ok2_yx")
  32. } else {
  33. self.opIconImageView.image = UIImage(named: "icon_add_1")
  34. }
  35. self.opIconImageView.isHidden = false
  36. }
  37. if let storeBoard = app.storyBoard, storeBoard == "webview" {
  38. if let iconUrl = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationIconQuery, parameter: ["##applicationId##":app.appId! as AnyObject]) {
  39. let url = URL(string: iconUrl)
  40. let size = self.appIconImageView.bounds.size
  41. if size.width == 0 {
  42. self.appIconImageView.bounds.size = CGSize(width: 38, height: 38)
  43. }
  44. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  45. self.appIconImageView.highlightedImage = UIImage(named: app.normalIcon!)
  46. self.appIconImageView.hnk_setImageFromURL(url!, placeholder: UIImage(named: app.normalIcon!), format: nil, failure: { (err) in
  47. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  48. }) { image in
  49. if self.nowData?.appId == app.appId {
  50. self.appIconImageView.image = image
  51. }
  52. }
  53. } else{
  54. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  55. self.appIconImageView.highlightedImage = UIImage(named: app.selectedIcon!)
  56. }
  57. } else{
  58. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  59. self.appIconImageView.highlightedImage = UIImage(named: app.selectedIcon!)
  60. }
  61. self.appTitle.text = app.title
  62. }
  63. }