zoukankan      html  css  js  c++  java
  • 性别年龄的模块封装类 IDSGenderLeviNamedView

    1 IDSGenderLeviNamedView 的实现效果
     
    EE8E7B25 DEBD 4371 B961 07EE1833D861
     
    2 类的封装方法:
     
    IDSGenderLeviNamedView.h
     
    @interface IDSGenderLeviNamedView : UIView
     
    @property (nonatomic, strong) UILabel *ageLabel;
     
    @property (nonatomic, strong) UIImageView *genderImageView;
     
    - (instancetype)initWithGender:(NSInteger)gender age:(NSInteger)age;
     
    - (void)gender:(NSInteger)gender age:(NSInteger)age;
     
    @end
     
    IDSGenderLeviNamedView.m
     
    #import "IDSGenderLeviNamedView.h"
     
    @implementation IDSGenderLeviNamedView
     
    #pragma mark - 初始化需求函数
     
    - (instancetype)initWithGender:(NSInteger)gender age:(NSInteger)age
    {
        if (self = [superinit]) {
            self.genderImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(3, 2, 10, 10)];
            if (gender == 0) {
                self.genderImageView.image = IDSImageNamed(@"img_yiqiwan_man");
                self.backgroundColor = NF_Color_C32;
            }
            else {
                self.genderImageView.image = IDSImageNamed(@"img_yiqiwan_woman");
                self.backgroundColor = NF_Color_C30;
            }
            self.genderImageView.contentMode = UIViewContentModeScaleAspectFill;
            [selfaddSubview:self.genderImageView];
            self.ageLabel = [[UILabelalloc] init];
            self.ageLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T1];
            self.ageLabel.textColor = NF_Color_C1;
            if (age) {
                self.ageLabel.text = [NSStringstringWithFormat:@"%ld",age];
                self.ageLabel.frame = CGRectMake(CGRectGetMaxX(self.genderImageView.frame)+1, 0, 0, 0);
                self.ageLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T1];
                self.ageLabel.textColor = NF_Color_C1;
                [self.ageLabelsizeToFit];
                self.ageLabel.centerY = self.genderImageView.centerY;//测试一下可行不?
                [selfaddSubview:self.ageLabel];
                self.frame = CGRectMake(0, 0, CGRectGetMaxX(self.ageLabel.frame)+3, 14);
            }
            else {
                self.frame = CGRectMake(0, 0, CGRectGetMaxX(self.genderImageView.frame)+3, 14);
            }
           
            self.layer.cornerRadius = 3.0f;
            self.layer.masksToBounds = YES;
            self.clipsToBounds = YES;
        }
        returnself;
    }
     
    - (void)gender:(NSInteger)gender age:(NSInteger)age
    {
        self.genderImageView.frame = CGRectMake(3, 2, 10, 10);
        if (gender == 0) {
            self.genderImageView.image = IDSImageNamed(@"img_yiqiwan_man");
            self.backgroundColor = NF_Color_C32;
        }
        else {
            self.genderImageView.image = IDSImageNamed(@"img_yiqiwan_woman");
            self.backgroundColor = NF_Color_C30;
        }
        self.genderImageView.contentMode = UIViewContentModeScaleAspectFill;
       
        self.ageLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T1];
        self.ageLabel.textColor = NF_Color_C1;
        if (age) {
            self.ageLabel.hidden = NO;
            self.ageLabel.text = [NSStringstringWithFormat:@"%ld",age];
            self.ageLabel.frame = CGRectMake(CGRectGetMaxX(self.genderImageView.frame)+1, 0, 0, 0);
            self.ageLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T1];
            self.ageLabel.textColor = NF_Color_C1;
            [self.ageLabelsizeToFit];
            self.ageLabel.centerY = self.genderImageView.centerY;//测试一下可行不?
            self.frame = CGRectMake(0, 0, CGRectGetMaxX(self.ageLabel.frame)+3, 14);
        }
        else {
            self.ageLabel.hidden = YES;
            self.frame = CGRectMake(0, 0, CGRectGetMaxX(self.genderImageView.frame)+3, 14);
        }
       
        self.layer.cornerRadius = 3.0f;
        self.layer.masksToBounds = YES;
        self.clipsToBounds = YES;
    }
     
    @end
     
     
    - OVER
  • 相关阅读:
    分布式框架服务调用超时设计与实现
    分布式框架灰度发布实现
    写给自己的 SOA 和 RPC 理解
    Java 基础【19】代理
    Java 基础【18】 反射与内省
    Spring HttpInvoker 从实战到源码追溯
    Lombok 使用攻略
    Guava Preconditions 工具参数前置校验
    CAS 单点登录【2】自定义用户验证
    Hibernate 离线对象构建通用查询
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888089.html
Copyright © 2011-2022 走看看