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
API description
// The default AntUI iconfont name.
#define kICONFONT_FONTNAME (@"auiconfont")
// The default AntUI iconfont path.
#define kICONFONT_FONTPATH (@"APCommonUI.bundle/iconfont/auiconfont")
/**
The iconfont control, which can be used as an ImageView.
Actually, the control 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 as 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.
*/
@interface AUIconView : UIImageView
@property (nonatomic, strong) UIColor *color; // The vector diagram color (ant blue by default).
@property (nonatomic, strong) NSString *name; // The vector diagram name.
@property (nonatomic, strong) NSString *fontName; // The vector icon library name.
/**
The initialization method.
@param frame The view frame.
@param name The iconfont vector icon name.
@return Return an AUIconView instance.
*/
- (instancetype)initWithFrame:(CGRect)frame name:(NSString *)name;
/**
The initialization method.
(If the iconfont has been loaded, it can be rendered without fontPath.)
@param frame The view frame.
@param name The iconfont image name.
@param fontName The iconfont name.
@return Return an AUIconView instance.
*/
- (instancetype)initWithFrame:(CGRect)frame name:(NSString *)name fontName:(NSString *)fontName;
/**
Get the iconView size.
@return If an iconfont is used, the iconfont size is returned. If an common ImageView is used, the image size is returned.
*/
- (CGSize)iconViewSize;
@end
@interface UIImage (AUIconFont)
/**
Register the iconfont. (This method needs to be called only once.)
@param fontName The iconfont name.
@param fontPath The iconfont path, such as @"AntUI.bundle/iconfont/auiconfont".
*/
+ (void)registerIconFont:(NSString *)fontName fontPath:(NSString *)fontPath;
/**
Get a square vector icon (with the same width and length).
@param name The image name.
@param width The image width.
@param color The image color. If the value is nil, the color is ant blue by default.
@return Return a square vector icon.
*/
+ (UIImage *)iconWithName:(NSString *)name
width:(CGFloat)width
color:(UIColor *)color;
/**
Get a square vector icon (with the same width and length).
@param name The name.
@param fontName The vector font name.
@param width The size.
@param color The image color. If nil is imported, the color is ant blut by default.
@return Return a square vector icon.
*/
+ (UIImage *)iconWithName:(NSString *)name
fontName:(NSString *)fontName
width:(CGFloat)width
color:(UIColor *)color;
@end
Sample code
// Use AUIconView.
AUIconView *view = [[AUIconView alloc] initWithFrame:CGRectZero name:_array[indexPath.row]];
view.tag = 1;
view.size = CGSizeMake(30, 30);
view.origin = CGPointMake(100, 10);
view.color = RGB(0x2b91e2);
[cell.contentView addSubview:view];
// Use the image extension independently.
self.image = [UIImage iconWithName:self.name fontName:self.fontName width:width color:self.color];