XYCountry.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // XYCountry.m
  3. // XYCountryCode
  4. //
  5. // Created by 杨卢银 on 2018/8/16.
  6. // Copyright © 2018年 杨卢银. All rights reserved.
  7. //
  8. #import "XYCountry.h"
  9. @interface XYCountry ()
  10. @property (strong , nonatomic)NSDictionary *info;
  11. @end
  12. @implementation XYCountry
  13. -(instancetype)initWithDictionary:(NSDictionary *)aInfo{
  14. self = [super init];
  15. if (self) {
  16. _info = aInfo;
  17. _imageName = _info[@"locale"];
  18. _code = [_info[@"code"] stringValue];
  19. _en = _info[@"en"];
  20. _zh = _info[@"zh"];
  21. _tw = _info[@"tw"];
  22. }
  23. return self;
  24. }
  25. -(NSString *)name{
  26. if (!_name) {
  27. NSLocale *locale = [NSLocale currentLocale];
  28. //en_US zh_CN zh_CN
  29. if([locale.localeIdentifier isEqualToString:@"zh-TW"] || [locale.localeIdentifier isEqualToString:@"zh-HK"]){
  30. _name = _info[@"tw"];
  31. }else if([locale.localeIdentifier isEqualToString:@"zh-CH"] || [locale.localeIdentifier isEqualToString:@"en_CN"]){
  32. _name = _info[@"zh"];
  33. }else{
  34. _name = _info[@"en"];
  35. }
  36. }
  37. return _name;
  38. }
  39. -(UIImage *)image{
  40. if (!_image) {
  41. NSString *bundlePath = [[NSBundle mainBundle]pathForResource:@"XYCountryCode"ofType:@"bundle"];
  42. NSBundle *resourceBundle = [NSBundle bundleWithPath:bundlePath];
  43. NSString *filename = [NSString stringWithFormat:@"Images/%@",_imageName];
  44. NSString *path = [resourceBundle pathForResource:filename ofType:@"png"];
  45. _image = [UIImage imageWithContentsOfFile:path];
  46. }
  47. return _image;
  48. }
  49. @end