美文网首页
星级评论控件

星级评论控件

作者: qilinit | 来源:发表于2016-08-05 06:54 被阅读22次

.m文件

#import "Start.h"

@implementation Start

-(void)setPercent:(CGFloat)percent

{

_percent = percent;

[self setNeedsDisplay];

}

-(void)drawRect:(CGRect)rect

{

[super drawRect:rect];

UIImage *image = [UIImage imageNamed:@"start"];

for (int i = 0; i < 5; i++) {

CGRect newRect = CGRectMake(i*0.2*rect.size.width, 0, 0.2*rect.size.width, rect.size.height );

[image drawInRect:newRect];

}

[[UIColor whiteColor] set];

UIRectFillUsingBlendMode(rect, kCGBlendModeSourceIn);

CGRect newRect= CGRectMake(0, 0, self.percent*rect.size.width, rect.size.height);

[[UIColor orangeColor] set];

UIRectFillUsingBlendMode(newRect, kCGBlendModeSourceIn);

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

CGFloat xPoint = [[touches anyObject]locationInView:self].x;

[self setPercent:xPoint/self.bounds.size.width];

}

@end

.h文件

#import

@interface Start : UIView

@property(nonatomic,assign)CGFloat percent;

@end

demo代码地址:https://yunpan.cn/cReHb4CSMdtdj (提取码:5cd5)

相关文章

网友评论

      本文标题:星级评论控件

      本文链接:https://www.haomeiwen.com/subject/vregdttx.html