O2CollectionViewCell.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 appTitle: UILabel!
  16. private var nowData:O2App?
  17. override func prepareForReuse() {
  18. super.prepareForReuse()
  19. self.appIconImageView.image = nil
  20. }
  21. func setAppData(app: O2App) {
  22. self.nowData = app
  23. if let storeBoard = app.storyBoard, storeBoard == "webview" {
  24. if let iconUrl = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationIconQuery, parameter: ["##applicationId##":app.appId! as AnyObject]) {
  25. let url = URL(string: iconUrl)
  26. let size = self.appIconImageView.bounds.size
  27. if size.width == 0 {
  28. self.appIconImageView.bounds.size = CGSize(width: 38, height: 38)
  29. }
  30. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  31. self.appIconImageView.highlightedImage = UIImage(named: app.normalIcon!)
  32. self.appIconImageView.hnk_setImageFromURL(url!, placeholder: UIImage(named: app.normalIcon!), format: nil, failure: { (err) in
  33. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  34. }) { image in
  35. if self.nowData?.appId == app.appId {
  36. self.appIconImageView.image = image
  37. }
  38. }
  39. } else{
  40. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  41. self.appIconImageView.highlightedImage = UIImage(named: app.selectedIcon!)
  42. }
  43. } else{
  44. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  45. self.appIconImageView.highlightedImage = UIImage(named: app.selectedIcon!)
  46. }
  47. self.appTitle.text = app.title
  48. }
  49. }