All Products
Search
Document Center

Mobile Platform as a Service:Icon component

Last Updated:May 25, 2021

AUIconView is an iconfont vector icon control. The usage is similar to that of UIImage.The control, which can be used as an ImageView, is an image object drawn by using the drawRect feature of the string.

Note: Currently, only square vector icons are supported.
  • You can consider that an iconfont loads a font. The font is associated with multiple images and each image has a Unicode character. Therefore, you can set text to the corresponding Unicode character and call the drawInRect method of the string to render the iconfont.
  • Each iconfont set is a .ttf font file. You can load multiple .ttf font files, each of which has a name. The default iconfont is the ttf font of AntUI, named auiconfont.

Sample image

icon

API description

  1. // The default AntUI iconfont name.
  2. #define kICONFONT_FONTNAME (@"auiconfont")
  3. // The default AntUI iconfont path.
  4. #define kICONFONT_FONTPATH (@"APCommonUI.bundle/iconfont/auiconfont")
  5. /**
  6. The iconfont control, which can be used as an ImageView.
  7. Actually, the control is an image object drawn by using the drawRect feature of the string.
  8. Note: Currently, only square vector icons are supported.
  9. You can consider that an iconfont loads a font. The font is associated with multiple images and each image has a Unicode character.
  10. Therefore, you can set text as the corresponding Unicode character and call the drawInRect method of the string to render the iconfont.
  11. Each iconfont set is a .ttf font file. You can load multiple
  12. .ttf font files, each of which has a name. The default iconfont is the ttf font of AntUI,
  13. named auiconfont.
  14. */
  15. @interface AUIconView : UIImageView
  16. @property (nonatomic, strong) UIColor *color; // The vector diagram color (ant blue by default).
  17. @property (nonatomic, strong) NSString *name; // The vector diagram name.
  18. @property (nonatomic, strong) NSString *fontName; // The vector icon library name.
  19. /**
  20. The initialization method.
  21. @param frame The view frame.
  22. @param name The iconfont vector icon name.
  23. @return Return an AUIconView instance.
  24. */
  25. - (instancetype)initWithFrame:(CGRect)frame name:(NSString *)name;
  26. /**
  27. The initialization method.
  28. (If the iconfont has been loaded, it can be rendered without fontPath.)
  29. @param frame The view frame.
  30. @param name The iconfont image name.
  31. @param fontName The iconfont name.
  32. @return Return an AUIconView instance.
  33. */
  34. - (instancetype)initWithFrame:(CGRect)frame name:(NSString *)name fontName:(NSString *)fontName;
  35. /**
  36. Get the iconView size.
  37. @return If an iconfont is used, the iconfont size is returned. If an common ImageView is used, the image size is returned.
  38. */
  39. - (CGSize)iconViewSize;
  40. @end
  41. @interface UIImage (AUIconFont)
  42. /**
  43. Register the iconfont. (This method needs to be called only once.)
  44. @param fontName The iconfont name.
  45. @param fontPath The iconfont path, such as @"AntUI.bundle/iconfont/auiconfont".
  46. */
  47. + (void)registerIconFont:(NSString *)fontName fontPath:(NSString *)fontPath;
  48. /**
  49. Get a square vector icon (with the same width and length).
  50. @param name The image name.
  51. @param width The image width.
  52. @param color The image color. If the value is nil, the color is ant blue by default.
  53. @return Return a square vector icon.
  54. */
  55. + (UIImage *)iconWithName:(NSString *)name
  56. width:(CGFloat)width
  57. color:(UIColor *)color;
  58. /**
  59. Get a square vector icon (with the same width and length).
  60. @param name The name.
  61. @param fontName The vector font name.
  62. @param width The size.
  63. @param color The image color. If nil is imported, the color is ant blut by default.
  64. @return Return a square vector icon.
  65. */
  66. + (UIImage *)iconWithName:(NSString *)name
  67. fontName:(NSString *)fontName
  68. width:(CGFloat)width
  69. color:(UIColor *)color;
  70. @end

Sample code

  1. // Use AUIconView.
  2. AUIconView *view = [[AUIconView alloc] initWithFrame:CGRectZero name:_array[indexPath.row]];
  3. view.tag = 1;
  4. view.size = CGSizeMake(30, 30);
  5. view.origin = CGPointMake(100, 10);
  6. view.color = RGB(0x2b91e2);
  7. [cell.contentView addSubview:view];
  8. // Use the image extension independently.
  9. self.image = [UIImage iconWithName:self.name fontName:self.fontName width:width color:self.color];