O2CollectionViewCell.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. func initImg(app:O2App){
  17. let storeBoard = app.storyBoard
  18. if storeBoard == "webview" {
  19. guard let iconUrl = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationIconQuery, parameter: ["##applicationId##":app.appId! as AnyObject]) else {
  20. DDLogError("没有获取到icon的url。。。。。。")
  21. return
  22. }
  23. let url = URL(string: iconUrl)
  24. let size = self.appIconImageView.bounds.size
  25. if size.width == 0 {
  26. self.appIconImageView.bounds.size = CGSize(width: 38, height: 38)
  27. }
  28. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  29. self.appIconImageView.highlightedImage = UIImage(named: app.normalIcon!)
  30. let cache = Shared.imageCache
  31. let format = HanekeGlobals.UIKit.formatWithSize(CGSize(width: 38, height: 38), scaleMode: .AspectFill)
  32. let formatName = format.name
  33. cache.addFormat(format)
  34. let fetcher = NetworkFetcher<UIImage>(URL: url!)
  35. cache.fetch(fetcher: fetcher, formatName: formatName).onSuccess { image in
  36. self.appIconImageView.image = image
  37. self.appIconImageView.highlightedImage = image
  38. }
  39. }else {
  40. self.appIconImageView.image = UIImage(named: app.normalIcon!)
  41. self.appIconImageView.highlightedImage = UIImage(named: app.normalIcon!)
  42. }
  43. }
  44. }