• 新浪微博客户端(33)-显示头像上的认证类型


    DJUser.h

    #import <Foundation/Foundation.h>
    
    typedef enum {
        
        DJUserVerifiedTypeNone = -1,                // 没有任何认证
        DJUserVerifiedTypePersonal = 0,             // 个人认证
        DJUserVerifiedTypeOrgEnterprise = 2,        // 企业官方
        DJUserVerifiedTypeOrgMedia = 3,             // 媒体官方
        DJUserVerifiedTypeWebsite = 5,              // 网站官方
        DJUserVerifiedTypeDaren = 220               // 微博达人
        
    } DJUserVerifiedType;
    
    /** 微博用户 */
    @interface DJUser : NSObject
    
    /** 当前用户ID */
    @property (nonatomic,copy) NSString *idstr;
    /** 当前用户名 */
    @property (nonatomic,copy) NSString *name;
    /** 当前用户缩略图头像 */
    @property (nonatomic,copy) NSString *profile_image_url;
    /** 会员等级 */
    @property (nonatomic,assign) int mbrank;
    /** 会员类型(大于2代表是会员) */
    @property (nonatomic,assign) int mbtype;
    /** 是否是会员 */
    @property (nonatomic,assign,getter=isVip) BOOL vip;
    /** 认证类型 */
    @property (nonatomic,assign) DJUserVerifiedType verified_type;
    
    @end

    DJIconView.m

    //
    //  DJIconView.m
    //  微博
    //
    //  Created by 海月高 on 16/11/23.
    //  Copyright © 2016年 yongdaimi. All rights reserved.
    //  用户头像
    
    #import "DJIconView.h"
    #import "DJUser.h"
    #import "UIImageView+WebCache.h"
    
    @interface DJIconView()
    
    @property (nonatomic,weak) UIImageView *verifiedView;
    
    @end
    
    @implementation DJIconView
    
    - (UIImageView *)verifiedView {
    
        if (!_verifiedView) {
            UIImageView *verifiedView = [[UIImageView alloc] init];
            [self addSubview:verifiedView];
            _verifiedView = verifiedView;
        }
        return _verifiedView;
    }
    
    
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            
        }
        return self;
    }
    
    
    
    
    - (void)setUser:(DJUser *)user {
    
        _user = user;
        
        // 设置用户头像
        [self sd_setImageWithURL:[NSURL URLWithString:user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]];
        
        // 设置用户类型
        switch (user.verified_type) {
            case DJUserVerifiedTypePersonal:      //个人认证
                self.verifiedView.hidden = NO;
                self.verifiedView.image = [UIImage imageNamed:@"avatar_vip"];
                break;
            case DJUserVerifiedTypeOrgEnterprise: // 企业官方
            case DJUserVerifiedTypeOrgMedia:      // 媒体官方
            case DJUserVerifiedTypeWebsite:       // 网站官方
                self.verifiedView.hidden = NO;
                self.verifiedView.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
                break;
            case DJUserVerifiedTypeDaren:        //  微博达人
                self.verifiedView.hidden = NO;
                self.verifiedView.image = [UIImage imageNamed:@"avatar_grassroot"];
                break;
            default:
                self.verifiedView.hidden = YES;
                break;
        }
        
    
    }
    
    
    
    - (void)layoutSubviews {
    
        [super layoutSubviews];
        
        CGFloat scale = 0.6;
        
        self.verifiedView.size = self.verifiedView.image.size;
        self.verifiedView.x = self.width - self.verifiedView.width * scale;
        self.verifiedView.y = self.height - self.verifiedView.height * scale;
        
    }
    
    
    
    @end

    最终效果:

     

  • 相关阅读:
    hibernate入门
    struts文件上传
    Struts的增删改查
    struts入门
    Maven配置以及环境搭配
    layui增删改查
    easyui三
    A
    C. Permutation Cycle
    E
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6095212.html
Copyright © 2020-2023  润新知