GitHub地址:https://github.com/runThor/HTDial
效果:
实现:
// 实际应用中,整个区域经常需要分为偏低区域、适中区域、偏高区域等不同的划分区域,要用不同的颜色标识,这里我们默认划分低、中、高三个区域,所以需要两个区域的间隔值
// HTDialView.h
#import <UIKit/UIKit.h>
@interface HTDialView : UIView
@property (nonatomic,assign)CGFloat minValue; // 表盘下限值
@property (nonatomic,assign)CGFloat maxValue; // 表盘上限值
@property (nonatomic,assign)CGFloat firstSeparationValue; // 第一个区域间隔值
@property (nonatomic,assign)CGFloat secondSeparationValue; // 第二个区域间隔值
// 设置指针指向的值
- (void)pointValue:(CGFloat)value;
@end
// HTDialView.m
#import "HTDialView.h"
@interface HTDialView ()
@property (nonatomic,strong)UIView *pointerView; // 指针
@end
@implementation HTDialView
- (void)drawRect:(CGRect)rect {
// 绘制划分区域
[self drawAreas];
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// 初始化视图
[self configViews];
}
return self;
}
// 初始化视图方法
- (void)configViews {
// 表盘轮廓
UIImageView *dialBgImgView = [[UIImageView alloc] initWithFrame:self.