版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1338188
// 先添加灰色的图片再添加橘色的图片
self.backgroundImage = [UIImageView alloc initWithFrame:CGRectMake(0, 0, 65, 23)];
self.backgroundImage.image = UIImage imageNamed:@"StarsBackground";
self addSubview:self.backgroundImage;
self.foregroundImage = [UIImageView alloc initWithFrame:CGRectMake(0, 0, 65, 23)];
self.foregroundImage.image = UIImage imageNamed:@"StarsForeground";
self addSubview:self.foregroundImage;
// 切割视图
self.foregroundImage.clipsToBounds = YES;
// 图片的停靠关系:左对齐
self.foregroundImage.contentMode = UIViewContentModeLeft;
// 实现星级的方法
{
self.foregroundImage.frame = CGRectMake(0, 0, self.backgroundImage.frame.size.width * level.floatValue / 5, 23);
}