RAHomeOrderModel.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // RAHomeOrderModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/1.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAHomeOrderModel.h"
  9. #import "UIImage+RedAnt.h"
  10. @implementation RAHomeOrderModel {
  11. UIImage *_icon;
  12. }
  13. - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
  14. }
  15. - (UIImage *)icon {
  16. return _icon;
  17. }
  18. - (void)setBackendFlag:(BOOL)backendFlag {
  19. _backendFlag = backendFlag;
  20. if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
  21. dispatch_async(dispatch_get_main_queue(), ^{
  22. [self.delegate refreshUI];
  23. });
  24. }
  25. }
  26. - (void)setIcon:(UIImage *)icon {
  27. _icon = icon;
  28. // _icon = [UIImage imageNamed:@"on_the_way"];
  29. if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
  30. dispatch_async(dispatch_get_main_queue(), ^{
  31. [self.delegate refreshUI];
  32. });
  33. }
  34. }
  35. //- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
  36. // [super setValuesForKeysWithDictionary:keyedValues];
  37. //
  38. // [self setIconURL:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536134884&di=9ea523019212b373ac04f4411e8aa56b&imgtype=jpg&er=1&src=http%3A%2F%2Fp3.music.126.net%2Fyp-UZgqWp6FV_AN4hPozjQ%3D%3D%2F109951163414711232.jpg"];
  39. //}
  40. - (void)setIconURL:(NSString *)iconURL {
  41. _iconURL = iconURL;
  42. if (_iconURL.length > 0 && [_iconURL hasPrefix:@"http"]) {
  43. __weak typeof(self) weakSelf = self;
  44. [RASingleton.sharedInstance.networkQueue addOperationWithBlock:^{
  45. UIImage *icon = [UIImage ra_imageWithURL:[NSURL URLWithString:iconURL]];
  46. icon = [self antiAlias:icon];
  47. if (weakSelf) {
  48. __strong typeof(weakSelf) strongSelf = weakSelf;
  49. [strongSelf setIcon:icon];
  50. }
  51. }];
  52. }
  53. }
  54. - (UIImage *)antiAlias:(UIImage *)img {
  55. CGFloat size = 70.0f;
  56. UIGraphicsBeginImageContextWithOptions(CGSizeMake(size, size), NO, [UIScreen mainScreen].scale);
  57. [img drawInRect:CGRectMake(0, 0, size, size)];
  58. UIImage *antialias = UIGraphicsGetImageFromCurrentImageContext();
  59. UIGraphicsEndImageContext();
  60. return antialias;
  61. }
  62. @end