BBABadgeValueView.h 4.19 KB
//
//  BBABadgeValueView.h
//  BBAPods
//
//  Created by Fan,Shuaifei on 2017/8/10.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import <UIKit/UIKit.h>

///飘新类型
typedef NS_ENUM(NSInteger, BBABadgeValueViewType) {
    /// 红色点飘新
    BBABadgeValueViewTypeDot,
    /// 数字飘信
    BBABadgeValueViewTypeNumber,
    /// 字符串飘新,直接显示给定字符串
    BBABadgeValueViewTypeString,
};

///飘新view边缘颜色类型
typedef NS_ENUM(NSInteger, BBABadgeValueViewBoaderType) {
    /// 灰色边缘,用于浅色背景飘新
    BBABadgeValueViewBoaderTypeGray,
    /// 黑色边缘,用于黑色背景飘新
    BBABadgeValueViewBoaderTypeBlack,
};

typedef NS_ENUM(NSUInteger, BBABadgeValueViewStyleType) {
    /// 常规飘新,有阴影字体小
    BBABadgeValueViewStyleTypeNormal = 0,
    /// 大飘新,无阴影字体大
    BBABadgeValueViewStyleTypeBigger,
};

/* 低精度范围
*   0<n<1w      ----- 显示具体数字
*   1w<=n<10w   ----- 以万单位保留1位小数,格式为"X.X万";当小数点后为0时显示整数
*   10w<=n<1亿   ----- 以万为单位保留整数,格式为"X万"
*   1亿<10亿     ----- 以亿单位保留1位小数,格式为"X.X亿";当小数点后为0时显示整数
*   10亿<n      -----  以亿单位保留整数,格式为"X亿"
*/
typedef NS_ENUM(NSUInteger, BBABadgeValueViewNumberPrecisionType) {
    /// 展示所有数字
    BBABadgeValueViewNumberPrecisionTypeAll,
    /// 默认,大于99展示99+
    BBABadgeValueViewNumberPrecisionTypeHundred,
    /// 大于999展示999+
    BBABadgeValueViewNumberPrecisionTypeThousand,
    /// 参考 底精度范围
    BBABadgeValueViewNumberPrecisionTypeScope
};


/**
 手百飘新组件
 使用方式:
 1. [BBABadgeValueView alloc] init];设置边框类型;
 2. 选择show方法;
 3. 需要更新显示内容updateBadgeValue: ;
 4. 删除飘新removeBadgeValue;
 */
@interface BBABadgeValueView : UIView

/// 飘新边框类型
@property(nonatomic, assign) BBABadgeValueViewBoaderType boaderType __attribute__((deprecated("this property has been deprecated and it's invalid to set it.")));

/// 飘新类型
@property(nonatomic, assign) BBABadgeValueViewType type;

/// 飘新样式,区分常规飘新/大飘新,默认 BBABadgeValueViewStyleTypeNormal
@property (nonatomic, assign) BBABadgeValueViewStyleType styleType;

/// 数字类型精度,默认 BBABadgeValueViewNumberPrecisionTypeHundred
@property (nonatomic, assign) BBABadgeValueViewNumberPrecisionType numberPrecisionType;
/// 飘新图片
@property(nonatomic, strong) UIImage *dotImage;

/**
 初始化飘新view,会自动计算出正确的bounds,add该view时frame的orgin需要自己计算

 @param badgeValue 飘新显示文字,如果type为BBABadgeValueViewTypeDot,可设置为nil
 @param type 飘信类型,支持三种
 @return 飘新view实例
 */
- (instancetype)initWithBadgeValue:(NSString *)badgeValue type:(BBABadgeValueViewType)type 
__attribute__((deprecated("this function has been deprecated please use showBadgeValue: inView: atPoint: type: instead")));

/**
 在指定的view显示指定类型飘新,显示在一个UI规范的默认位置

 @param badgeValue 飘新显示文字,如果type为BBABadgeValueViewTypeDot,可设置为nil
 @param view 飘新加在该view上(会根据UI给定的标准默认加在一个位置,如果不能满足需求,使用init方法,自己add)
 @param type 飘新类型
 */
- (void)showBadgeValue:(NSString *)badgeValue inView:(UIView *)view type:(BBABadgeValueViewType)type;

/**
 在指定view的指定位置显示指定类型飘新

 @param badgeValue 飘新显示文字,如果type为BBABadgeValueViewTypeDot,设置nil
 @param view 飘新加在该view上
 @param point 飘新在view上的orgin位置
 @param type 飘新类型
 */
- (void)showBadgeValue:(NSString *)badgeValue inView:(UIView *)view atPoint:(CGPoint)point type:(BBABadgeValueViewType)type;

/**
 更新飘新数字,保持原始飘新的orgin不变,更新bounds和文字,如果type为BBABadgeValueViewTypeDot,该接口什么都不做

 @param badgeValue 更新后的飘新值
 */
- (void)updateBadgeValue:(NSString *)badgeValue;

/**
 删除飘新,从父view移除
 */
- (void)removeBadgeValue;

@end