OOAppEditCell.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // OOAppEditCell.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/5/10.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class OOAppEditCell: UITableViewCell,Configurable {
  11. @IBOutlet weak var appIcon: UIImageView!
  12. @IBOutlet weak var appNameLabel: UILabel!
  13. override func awakeFromNib() {
  14. super.awakeFromNib()
  15. // Initialization code
  16. }
  17. override func setSelected(_ selected: Bool, animated: Bool) {
  18. super.setSelected(selected, animated: animated)
  19. // Configure the view for the selected state
  20. }
  21. func config(withItem item: Any?) {
  22. guard let app = item as? O2App else {
  23. return
  24. }
  25. //名字
  26. appNameLabel.text = app.title
  27. initImg(app: app)
  28. }
  29. private func initImg(app:O2App){
  30. let storeBoard = app.storyBoard
  31. if storeBoard == "webview" {
  32. guard let iconUrl = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationIconQuery, parameter: ["##applicationId##":app.appId! as AnyObject]) else {
  33. DDLogError("没有获取到icon的url。。。。。。")
  34. return
  35. }
  36. let url = URL(string: iconUrl)
  37. let size = self.appIcon.bounds.size
  38. if size.width == 0 {
  39. self.appIcon.bounds.size = CGSize(width: 38, height: 38)
  40. }
  41. self.appIcon.image = UIImage(named: app.normalIcon!)
  42. self.appIcon.highlightedImage = UIImage(named: app.normalIcon!)
  43. let cache = Shared.imageCache
  44. let format = HanekeGlobals.UIKit.formatWithSize(CGSize(width: 38, height: 38), scaleMode: .AspectFill)
  45. let formatName = format.name
  46. cache.addFormat(format)
  47. let fetcher = NetworkFetcher<UIImage>(URL: url!)
  48. cache.fetch(fetcher: fetcher, formatName: formatName).onSuccess { image in
  49. self.appIcon.image = image
  50. self.appIcon.highlightedImage = image
  51. }
  52. }else {
  53. self.appIcon.image = UIImage(named: app.normalIcon!)
  54. self.appIcon.highlightedImage = UIImage(named: app.normalIcon!)
  55. }
  56. }
  57. }