使用一个 UIView 显示一个长图中的某一部分图片

使用一个 UIView 显示一个长图中的某一部分图片

///获取等级view
+(UIView *)imageViewWithLevel:(NSInteger) level{
UIView *imageView = [[UIView alloc] init];
imageView.layer.contents = (__bridge id _Nullable)([[UIImage imageWithContentsOfFile:[self pathWithName:@”level.png”]] CGImage]);
static CGFloat wid = 40, hei = 16, off = 3, totalHei = 3588;
imageView.layer.contentsRect = CGRectMake(0, 0 * (hei + off) / totalHei, 1, hei/totalHei);
imageView.layer.contentsGravity = kCAGravityTop;
imageView.frame = CGRectMake(0, 0, wid, hei);
return imageView;
}
长图如下所示:这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_27074387/article/details/79187452