标签:技术 lazy status ace turn end 头像 def default
需求:全平台(整个APP)头像不同的vip级别添加不同的vip标识
样式:(圆形头像右下角添加vip标识)
为了便于调用,采用了 UIImageView 分类,添加方法,方法里添加一个 UIImageView 展示vip标识 的实现方式。直接上代码
1.新建 UIImageView+TJVipHead 分类
2..h里代码
@interface UIImageView (TJVipHead) @property(strong, nonatomic) UIImageView *vipMarkImageView;
/// VIP 标识宽度 默认 Ratio(16)*Ratio(16) /// @param vipLevel vip级别 /// @param vipStatus VIP 状态 -(void)addVipMarkWithVipLevel:(NSString *)vipLevel vipStatus:(NSString *)vipStatus;
@end |
3..m里代码
@implementation UIImageView (TJVipHead)
-(void)addVipMarkWithVipLevel:(NSString *)vipLevel vipStatus:(NSString *)vipStatus { if (![self.superview.subviews containsObject:self.vipMarkImageView]) { self.vipMarkImageView = [[UIImageView alloc] init]; self.vipMarkImageView.size=CGSizeMake(Ratio(16), Ratio(16)); self.vipMarkImageView.right=self.right; self.vipMarkImageView.bottom=self.bottom; self.vipMarkImageView.backgroundColor = [UIColor clearColor]; self.vipMarkImageView.userInteractionEnabled=YES; self.vipMarkImageView.image=nil; [self.superview addSubview:self.vipMarkImageView]; } [self.superview bringSubviewToFront:self.vipMarkImageView]; if (beNil(vipLevel)) { vipLevel=@"0"; } if (beNil(vipStatus)) { vipStatus=@"0"; } if (vipStatus.integerValue) { //vip有效 //vipLevel//会员级别 1:普通;2:高级;3:特级; switch (vipLevel.integerValue) { case 0: self.vipMarkImageView.image=nil; break; case 1: self.vipMarkImageView.image=[UIImage imageNamed:@"common_vip"]; break; case 2: self.vipMarkImageView.image=[UIImage imageNamed:@"common_vip_senior"]; break; case 3: self.vipMarkImageView.image=[UIImage imageNamed:@"common_vip_super"]; break; default: break; } } else { //vip失效或者没开通 self.vipMarkImageView.image=nil; } }
#pragma mark - Add a "vipMarkImageView" to this UIImageView class
NSString const *kKeyVipMarkImageView = @"kKeyVipMarkImageView"; -(void)setVipMarkImageView:(UIImageView *)vipMarkImageView { objc_setAssociatedObject(self, &kKeyVipMarkImageView, (id)vipMarkImageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(UIImageView *)vipMarkImageView { return objc_getAssociatedObject(self, &kKeyVipMarkImageView); }
@end |
标签:技术 lazy status ace turn end 头像 def default
原文地址:https://www.cnblogs.com/huangzs/p/13347655.html