iOS圖片和字符串合成Label展示筆記

實(shí)現(xiàn)效果

IMG_0069.PNG

缺點(diǎn)在于小屏幕適配當(dāng)中,當(dāng)9999.99數(shù)據(jù)較長的時(shí)候,文字會直接變成...

pod文件中

    pod 'YYKit'

實(shí)現(xiàn)方式

- (YYLabel *)douLab {
    if (_douLab == nil) {
        _douLab = [[YYLabel alloc]init];
        _douLab.displaysAsynchronously = YES;
        _douLab.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        NSMutableAttributedString *finalStr = [[NSMutableAttributedString alloc]init];
        UIFont *font = [UIFont systemFontOfSize:11];
//        NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
//        paragraphStyle.lineSpacing = 3;
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 14, 14)];
        image.image = [UIImage imageNamed:@"yz_charge_icon_zhongdou"];
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
        
        NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",_dou] attributes:@{NSForegroundColorAttributeName: UIColorHex(#303046),NSFontAttributeName:font}];
        [finalStr appendAttributedString:str];
        _douLab.frame = CGRectMake(0, 80, self.frame.size.width, 15);
        _douLab.attributedText = finalStr;
        _douLab.textAlignment = NSTextAlignmentCenter;
        _douLab.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
        
    }
    return _douLab;
}

附加禮物scrollview的實(shí)現(xiàn)

YZItemGiftView.m



#import "YZItemGiftView.h"


@interface YZItemGiftView()<UIGestureRecognizerDelegate>
@property(nonatomic,strong)UIView * colorLayerView;
@property(nonatomic,strong)UIImageView * heartImageView;
@property(nonatomic,strong)UILabel * titleInfoLab;
@property(nonatomic,strong)YYLabel * douLab;
@property(nonatomic,strong)NSString * dou;
@property(nonatomic,strong)NSString * url;
@property(nonatomic,strong)NSString * title;
@property(nonatomic,copy)YZGiftTapBlock block;
@end

@implementation YZItemGiftView

- (instancetype)initWithFrame:(CGRect)frame price:(NSString *)price imageUrl:(NSString *)url title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        _dou = @"9999.99";
//        _dou = price;
//        _url = url;
        _title = title;
        [self addSubview:self.colorLayerView];
        self.colorLayerView.hidden = YES;
        [self addSubview:self.heartImageView];
        [self addSubview:self.titleInfoLab];
        [self addSubview:self.douLab];
        [self.colorLayerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self);
        }];
        
        [_heartImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(4);
            make.centerX.equalTo(self);
            make.width.height.equalTo(@50);
        }];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap)];
        tap.delegate = self;
        [self addGestureRecognizer:tap];
    }
    return self;
    
}

-(void)clickTap {
   
}

-(UIImageView *)heartImageView {
    if (_heartImageView == nil) {
        _heartImageView = [[UIImageView alloc] init];
        _heartImageView.image = [UIImage imageNamed:@"yz_info_icon_gift"];
//        [_heartImageView sd_setImageWithURL:[NSURL URLWithString:_url]];
    }
    return _heartImageView;
}

-(UIView *)colorLayerView {
    if (_colorLayerView == nil) {
        _colorLayerView = [[UIView alloc] init];
        _colorLayerView.layer.cornerRadius = 5;
        _colorLayerView.layer.masksToBounds = YES;
        _colorLayerView.layer.borderWidth = 0.5;
        _colorLayerView.layer.borderColor = UIColorHex(#0E76F1).CGColor;
        _colorLayerView.backgroundColor = [UIColor whiteColor];
    }
    return _colorLayerView;
}
-(UILabel *)titleInfoLab {
    if (_titleInfoLab == nil) {
        _titleInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(2, 55, self.frame.size.width - 4, 25)];
        _titleInfoLab.text = @"給你棒棒糖";
//        _titleInfoLab.text = _title;
        _titleInfoLab.textAlignment = NSTextAlignmentCenter;
        _titleInfoLab.font = [UIFont systemFontOfSize:12];
        _titleInfoLab.textColor = UIColorHex(#303046);
        _titleInfoLab.adjustsFontSizeToFitWidth = YES;
    }
    return _titleInfoLab;
}

- (YYLabel *)douLab {
    if (_douLab == nil) {
        _douLab = [[YYLabel alloc]init];
        _douLab.displaysAsynchronously = YES;
        _douLab.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        NSMutableAttributedString *finalStr = [[NSMutableAttributedString alloc]init];
        UIFont *font = [UIFont systemFontOfSize:11];
//        NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
//        paragraphStyle.lineSpacing = 3;
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 14, 14)];
        image.image = [UIImage imageNamed:@"yz_charge_icon_zhongdou"];
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
        
        NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",_dou] attributes:@{NSForegroundColorAttributeName: UIColorHex(#303046),NSFontAttributeName:font}];
        [finalStr appendAttributedString:str];
        _douLab.frame = CGRectMake(0, 80, self.frame.size.width, 15);
        _douLab.attributedText = finalStr;
        _douLab.textAlignment = NSTextAlignmentCenter;
        _douLab.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
        
    }
    return _douLab;
}

- (void)setSelectStatus:(BOOL)selectStatus {
    _selectStatus = selectStatus;
    if (selectStatus) {
        self.colorLayerView.hidden = NO;
    }else {
        self.colorLayerView.hidden = YES;
    }
}

@end


YZItemGiftView.h


typedef void(^YZGiftTapBlock)(NSInteger);
@interface YZItemGiftView : UIView
@property(nonatomic,assign)BOOL selectStatus;

YZBannerGiftView.m



#import "YZBannerGiftView.h"
#import "YZItemGiftView.h"

@interface YZBannerGiftView()<UIScrollViewDelegate>
@property(nonatomic,strong)NSMutableArray * allArray;
@property(nonatomic,assign)NSInteger needCount;
@property(nonatomic,assign)CGFloat rateX;
@end

@implementation YZBannerGiftView
- (id)initWithFrame:(CGRect)frame :(NSArray*)array;
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _rateX = Screen_Width / 375;
        
        _allArray = [NSMutableArray arrayWithArray:array];
        if (_allArray.count % 8 == 0) {
            _needCount = _allArray.count / 8;
        }else {
            _needCount = _allArray.count / 8 + 1;
        }
        self.pageCount = _needCount;
        [self creatScrollView];
    }
    return self;
}

-(void)creatScrollView{
    self.bannerScroll = [[UIScrollView alloc]init];
    self.bannerScroll.frame = CGRectMake(0, 0,Screen_Width,224);
    [self addSubview:self.bannerScroll];
    
    self.bannerScroll.contentSize = CGSizeMake((_needCount)*Screen_Width, 0);
    self.bannerScroll.pagingEnabled = YES;
    self.bannerScroll.showsHorizontalScrollIndicator = NO ;
    self.bannerScroll.delegate = self ;
    self.bannerScroll.bounces = NO;
    
    for (int i = 0; i < _needCount+1; i++) {
        UIView * view = [[UIImageView alloc] initWithFrame:CGRectMake(i*Screen_Width, 0, Screen_Width, Screen_Height)];
        view.backgroundColor = [UIColor clearColor];
        [self.bannerScroll addSubview:view];
    }
    
    if ((Screen_Width - 4 * 90 ) > 0) {
        CGFloat innerMargin = (Screen_Width - 4 * 80) / 5;
      
        for (int i = 0; i < _allArray.count; i ++) {
            
            NSInteger locX = i / 8;
            NSInteger indexY = i % 8;
            CGFloat allY;
            if (indexY > 3) {
                allY = 10 + 100 + 4;
            }else {
                allY = 10;
            }
            
            NSInteger infoX = indexY % 4;
            
            CGFloat Xmini = innerMargin + infoX * (80 + innerMargin);
            CGFloat allX = Xmini + locX * Screen_Width;

        
            CGRect rect = CGRectMake(allX, allY, 80, 100);
            
            YZItemGiftView * item = [[YZItemGiftView alloc] initWithFrame:rect];
            [self.bannerScroll addSubview:item];
            
        }
        
    }else {
        CGFloat innerMargin = (Screen_Width - 4 * 80 * _rateX) / 5;
      
        for (int i = 0; i < _allArray.count; i ++) {
            
            NSInteger locX = i / 8;
            NSInteger indexY = i % 8;
            CGFloat allY;
            if (indexY > 3) {
                allY = 10 + 100 + 4;
            }else {
                allY = 10;
            }
            
            NSInteger infoX = indexY % 4;
            
            CGFloat Xmini = innerMargin + infoX * (80 * _rateX + innerMargin);
            CGFloat allX = Xmini + locX * Screen_Width;

        
            CGRect rect = CGRectMake(allX, allY, 80 * _rateX, 100);
            
            YZItemGiftView * item = [[YZItemGiftView alloc] initWithFrame:rect];
            [self.bannerScroll addSubview:item];
            
        }
    }
    
    
    
    
    

    
    self.bannerPageControl = [[UIPageControl alloc] init];
    self.bannerPageControl.frame = CGRectMake(0, 224 - 25, Screen_Width, 25);
    self.bannerPageControl.numberOfPages = self.pageCount;
    self.bannerPageControl.currentPage = 0;
    self.bannerPageControl.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];;
    self.bannerPageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [self addSubview:self.bannerPageControl];

}




- (void)changeScrollOffset {
    [self.bannerScroll setContentOffset:CGPointMake((self.bannerPageControl.currentPage+1) * Screen_Width, 0) animated:YES];
}



#pragma  mark **************UIScrollViewDelegate*******************
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint point = scrollView.contentOffset;
    BOOL isRight = self.oldScrollOffset < point.x;
    self.oldScrollOffset = point.x;
    // 調(diào)整pageControl的當(dāng)前 位置
    if (point.x > Screen_Width*(self.pageCount-1)+Screen_Width*0.5) {
        self.bannerPageControl.currentPage = 0;
    }else if (point.x > Screen_Width*(self.pageCount-1)  && isRight){
        self.bannerPageControl.currentPage = 0;
    }else{
        self.bannerPageControl.currentPage = (point.x+Screen_Width*0.5)/ Screen_Width;
    }
    
    //處理兩種情況,1壁却、當(dāng)偏移量超出scrollView contentSize最大值時(shí) 2劲绪、當(dāng)偏移量小于零時(shí)
    if (point.x >= Screen_Width*self.pageCount) {
        
//        [scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
        
    }else if (point.x < 0) {
        
//        [scrollView setContentOffset:CGPointMake(point.x+Screen_Width*(self.pageCount), 0) animated:NO];
    }
}
/**
 手指開始拖動的時(shí)候, 就讓計(jì)時(shí)器停止
 */
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    
 
}
/**
 手指離開屏幕的時(shí)候, 就讓計(jì)時(shí)器開始工作
 */
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    
}

@end

YZBannerGiftView.h


#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface YZBannerGiftView : UIView
@property(strong ,nonatomic) UIScrollView  *  bannerScroll; //滾動視圖
@property(strong ,nonatomic) UIPageControl *  bannerPageControl; //分頁指示控件
//@property(strong ,nonatomic) NSArray       *  bannerArray;   //輪播圖name數(shù)組
@property(assign ,nonatomic) NSUInteger       pageCount ;   //記錄總頁面數(shù)
@property(assign ,nonatomic) NSUInteger       CurrentPageCount ; //記錄當(dāng)前的頁面
@property(assign ,nonatomic) float            oldScrollOffset;   //記錄之前Scroll偏移量
- (id)initWithFrame:(CGRect)frame :(NSArray*)array;
@end

NS_ASSUME_NONNULL_END

YZLiveGiftView.m

#import "YZLiveGiftView.h"
#import "YZBannerGiftView.h"

@interface YZLiveGiftView()<UIGestureRecognizerDelegate>

@property(nonatomic,assign)CGFloat rateX;
@property(nonatomic,strong)UIView * blackView;
@property(nonatomic,strong)UIView * bottomContentView;

@end

@implementation YZLiveGiftView

+(YZLiveGiftView *)show{
    YZLiveGiftView * view = [[YZLiveGiftView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:view];
    return view;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _rateX = Screen_Width / 375;
        [self addSubview:self.blackView];
        [self addSubview:self.bottomContentView];
    }
    return self;
}

-(UIView *)blackView {
    if (_blackView == nil) {
        _blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
        _blackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remove)];
        tap.delegate = self;
        [_blackView addGestureRecognizer:tap];
    }
    return _blackView;
}

-(void)remove {
    [self removeFromSuperview];
}

-(UIView *)bottomContentView {
    if (_bottomContentView == nil) {
        _bottomContentView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height - 224 - 50 - SafeAreaBottomHeight, Screen_Width, 224)];
        _bottomContentView.backgroundColor = [UIColor whiteColor];
        NSMutableArray * array = [NSMutableArray arrayWithCapacity:0];
        for (int i = 0 ; i < 10 ; i ++) {
            [array addObject:@(i)];
        }
        YZBannerGiftView * view = [[YZBannerGiftView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 224) :array];
        [_bottomContentView addSubview:view];
    }
    return _bottomContentView;
}

@end

YZLiveGiftView.h

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface YZLiveGiftView : UIView

+(YZLiveGiftView *)show;

@end

NS_ASSUME_NONNULL_END

另外一個(gè)圖片和文字組合成為一張圖片的組合方式

YZHeadImg.h

#import <Foundation/Foundation.h>
#import "YZHeadImageView.h"

NS_ASSUME_NONNULL_BEGIN

@interface YZHeadImg : NSObject
+ (UIImage*)imageWithFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size leavel:(NSString *)leavel;

+ (UIImage*)zbjimageWithFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size leavel:(NSString *)leavel;

@end

NS_ASSUME_NONNULL_END

YZHeadImg.m

#import "YZHeadImg.h"

@implementation YZHeadImg
+ (UIImage *)imageWithFrame:(CGRect)frame BackGroundColor:(UIColor *)backGroundColor Text:(NSString *)text TextColor:(UIColor *)textColor TextFontOfSize:(CGFloat)size leavel:( NSString *)leavel{
//初始化并繪制UI
    YZHeadImageView *view = [[YZHeadImageView alloc] initWithFrame:frame BackGroundColor:backGroundColor Text:text TextColor:textColor TextFontOfSize:size lvleavel:leavel];

//轉(zhuǎn)化成image
//    UIGraphicsBeginImageContext(view.bounds.size);
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:ctx];
    UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tImage;
}

+ (UIImage *)zbjimageWithFrame:(CGRect)frame BackGroundColor:(UIColor *)backGroundColor Text:(NSString *)text TextColor:(UIColor *)textColor TextFontOfSize:(CGFloat)size leavel:( NSString *)leavel{
//初始化并繪制UI
    YZHeadImageView *view = [[YZHeadImageView alloc] initWithzbjFrame:frame BackGroundColor:backGroundColor Text:text TextColor:textColor TextFontOfSize:size lvleavel:leavel];

//轉(zhuǎn)化成image
//    UIGraphicsBeginImageContext(view.bounds.size);
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:ctx];
    UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tImage;
}

@end

YZHeadImageView.m

#import "YZHeadImageView.h"

@implementation YZHeadImageView
- (id)initWithFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size lvleavel:(NSString *)leavl{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *backView = [[UIView alloc] initWithFrame:frame];
        backView.backgroundColor = backGroundColor;
        [self addSubview:backView];
        
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:frame];

        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"yz_fans_icon_fshz_%@",leavl]];

        [backView addSubview:imageView];
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12, 0.5, 31, 13)];
        label.text = text;
        label.textColor = textColor;
        label.backgroundColor = backGroundColor;
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:size];
        [backView addSubview:label];
    }
    return self;
}

- (id)initWithzbjFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size lvleavel:(NSString *)leavl {
    self = [super initWithFrame:frame];
    if (self) {
        UIView *backView = [[UIView alloc] initWithFrame:frame];
        backView.backgroundColor = backGroundColor;
        [self addSubview:backView];
        
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:frame];

        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"yz_fans_icon_fshz_%@",leavl]];

        [backView addSubview:imageView];
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(7, 0, 27, 12)];
        label.text = text;
        label.textColor = textColor;
        label.backgroundColor = backGroundColor;
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:size];
        [backView addSubview:label];
    }
    return self;
}
@end

YZHeadImageView.h

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface YZHeadImageView : UIView
- (id)initWithFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size lvleavel:(NSString *)leavl;
- (id)initWithzbjFrame:(CGRect)frame BackGroundColor:(UIColor*)backGroundColor Text:(NSString*)text TextColor:(UIColor*)textColor TextFontOfSize:(CGFloat)size lvleavel:(NSString *)leavl;

@end

NS_ASSUME_NONNULL_END

用法:


        UIImage *imageTest = [YZHeadImg imageWithFrame:CGRectMake(0, 0, 45, 13) BackGroundColor:[UIColor clearColor] Text:model.badgetitle TextColor:[UIColor whiteColor] TextFontOfSize:7 leavel:model.badgelevel];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 45 ,13)];
        imageView.image = imageTest;

效果:

IMG_0070.jpg

另外一個(gè)cell的展示是直播中的彈幕消息的實(shí)現(xiàn)

#import "YZRoomDeleListCell.h"
@interface YZRoomDeleListCell()<UIGestureRecognizerDelegate>
@property(nonatomic,strong)UIImageView * headImg;
@property(nonatomic,strong)UILabel * nameLab;
@property(nonatomic,strong)UILabel * douLab;
@property(nonatomic,strong)UIView * lineView;
@property(nonatomic, strong) YYLabel *specialLab;
@property(nonatomic,strong)NSString * yzdwImgStr;
@property(nonatomic,assign)NSInteger index;
@end
@implementation YZRoomDeleListCell




+ (instancetype)cellWithTableView:(UITableView *)tableView index:(NSInteger)index
{
    static NSString *identifier = @"YZFansContributeCell";
    // 1.緩存中取
    YZRoomDeleListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.創(chuàng)建
    if (cell == nil) {
        cell = [[YZRoomDeleListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier index:index];
    }
    return cell;
    
}


/**
 *  構(gòu)造方法(在初始化對象的時(shí)候會調(diào)用)
 *  一般在這個(gè)方法中添加需要顯示的子控件
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier index:(NSInteger)index
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.cornerRadius = 3;
        self.layer.masksToBounds = YES;
        _index = index;
        [self.contentView addSubview:self.headImg];
        [self.contentView addSubview:self.nameLab];
        [self.contentView addSubview:self.specialLab];
        [self.contentView addSubview:self.douLab];
        [self.contentView addSubview:self.lineView];
        [self configFrameLayout];
    }
    return self;
}






-(UIImageView *)headImg {
    if (_headImg == nil) {
        _headImg = [[UIImageView alloc] init];
                [_headImg sd_setImageWithURL:[NSURL URLWithString:@"http://zhongyou-source.oss-cn-hangzhou.aliyuncs.com/file/2021/04/02/161733533962.png"]];
        _headImg.layer.cornerRadius = 15;
        _headImg.layer.masksToBounds = YES;
        
    }
    return _headImg;
}

-(UILabel *)nameLab {
    if (_nameLab == nil) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.text = @"木蘭花海";
        _nameLab.textColor = UIColorHex(#303046);
        _nameLab.font = [UIFont systemFontOfSize:14];
        _nameLab.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLab;
}


-(UILabel *)douLab {
    if (_douLab == nil) {
        _douLab = [[UILabel alloc] init];
        if (_index == 0) {
            _douLab.text = @"移除房管";
            _douLab.textColor = UIColorHex(#0E76F1);

            _douLab.layer.borderColor = UIColorHex(#0E76F1).CGColor;
        }else if (_index == 1){
            _douLab.text = @"解除禁言";
            _douLab.textColor = UIColorHex(#FF3F57);

            _douLab.layer.borderColor = UIColorHex(#FF3F57).CGColor;
        }else if (_index == 2){
            _douLab.text = @"解除踢出";
            _douLab.textColor = UIColorHex(#0E76F1);
            _douLab.layer.borderColor = UIColorHex(#0E76F1).CGColor;
        }else if (_index == 3){
            _douLab.text = @"卸任房管";
            _douLab.textColor = UIColorHex(#0E76F1);
            _douLab.layer.borderColor = UIColorHex(#0E76F1).CGColor;
            _douLab.backgroundColor = UIColorHex(#F5FAFF);
        }
        _douLab.layer.cornerRadius = 12.5;
        _douLab.layer.masksToBounds = YES;
        _douLab.layer.borderWidth = 0.5;
        _douLab.font = [UIFont systemFontOfSize:12];
        _douLab.textAlignment = NSTextAlignmentCenter;
        _douLab.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(douAction)];
        tap.delegate = self;
        [_douLab addGestureRecognizer:tap];
    }
    return _douLab;
}

-(void)douAction {
    [ToastUtils showMessage:@"remove" duration:1 position:Toast_Point_Center];
}

- (void)setModel:(YZFansTrueLoveModel *)model{
   
    _model = model;
    
    _nameLab.text = model.nickname;
//    _douLab.text = [NSString stringWithFormat:@"解除房管"];
    [_headImg sd_setImageWithURL:[NSURL URLWithString:model.avatar]];

    NSMutableAttributedString *finalStr = [[NSMutableAttributedString alloc]init];
    UIFont *font = [UIFont systemFontOfSize:12];
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = 3;


    if(model.gradeimg.isNotBlank){
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 15)];
        [image sd_setImageWithURL:[NSURL URLWithString:model.gradeimg]];
        // 測試數(shù)據(jù)
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
    }

    if ([model.grouplevel integerValue] > 0) {
        UIImage *imageTest = [YZHeadImg imageWithFrame:CGRectMake(0, 0, 45, 13) BackGroundColor:[UIColor clearColor] Text:model.badgetitle TextColor:[UIColor whiteColor] TextFontOfSize:7 leavel:model.badgelevel];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 45 ,13)];
        imageView.image = imageTest;
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeCenter attachmentSize:imageView.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
    }

    self.specialLab.attributedText = finalStr;

    YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(Screen_Width - 100, MAXFLOAT)];
    YYTextLayout *textLayout = [YYTextLayout layoutWithContainer:container text:self.specialLab.attributedText];
    self.specialLab.textLayout = textLayout;

    self.specialLab.frame = CGRectMake(50,29, textLayout.textBoundingSize.width, textLayout.textBoundingSize.height);

}

- (void)setInfoModel:(YZRoomDeleteModel *)infoModel {
    _infoModel = infoModel;
    
    _nameLab.text = _infoModel.nickname;
//    _douLab.text = [NSString stringWithFormat:@"解除房管"];
    [_headImg sd_setImageWithURL:[NSURL URLWithString:_infoModel.avatar]];

    NSMutableAttributedString *finalStr = [[NSMutableAttributedString alloc]init];
    UIFont *font = [UIFont systemFontOfSize:12];
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = 3;


    if(_infoModel.smallimage.isNotBlank){
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 15)];
        [image sd_setImageWithURL:[NSURL URLWithString:_infoModel.smallimage]];
        // 測試數(shù)據(jù)
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
    }

    if (_infoModel.level > 0) {
        UIImage *imageTest = [YZHeadImg imageWithFrame:CGRectMake(0, 0, 45, 13) BackGroundColor:[UIColor clearColor] Text:_infoModel.groupname TextColor:[UIColor whiteColor] TextFontOfSize:7 leavel:[NSString stringWithFormat:@"%d",_infoModel.level]];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 45 ,13)];
        imageView.image = imageTest;
        NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeCenter attachmentSize:imageView.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
        [finalStr appendAttributedString:attachText];
    }

    self.specialLab.attributedText = finalStr;

    YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(Screen_Width - 100, MAXFLOAT)];
    YYTextLayout *textLayout = [YYTextLayout layoutWithContainer:container text:self.specialLab.attributedText];
    self.specialLab.textLayout = textLayout;

    self.specialLab.frame = CGRectMake(50,29, textLayout.textBoundingSize.width, textLayout.textBoundingSize.height);
    
}


-(void)configFrameLayout {

        [_headImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.centerY.equalTo(self);
            make.width.height.equalTo(@30);
        }];
    
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(6);
        make.left.equalTo(_headImg.mas_right).offset(5);
        make.width.greaterThanOrEqualTo(@10);
        make.height.equalTo(@23);
    }];
    
    [_douLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@25);
        make.width.equalTo(@65);
        make.centerY.equalTo(self);
    }];
}

-(UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(15, 49.5, Screen_Width - 30, 0.5)];
        _lineView.backgroundColor = UIColorHex(#EEEEEE);
    }
    return _lineView;
}


- (YYLabel *)specialLab {
    
    if (_specialLab == nil) {
        _specialLab = [[YYLabel alloc]init];
        _specialLab.numberOfLines = 0;
        _specialLab.textAlignment = NSTextAlignmentLeft;
        _specialLab.lineBreakMode = NSLineBreakByCharWrapping;
        _specialLab.displaysAsynchronously = YES;
        _specialLab.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    }
    return _specialLab;
}


-(void)getServiceData {
    NSString * url = @"";
    if (_index == 0) {
        url = URL_YZ_anchor_room_delete_0;
    }else if (_index == 1){
        url = URL_YZ_anchor_room_delete_1;
    }else if (_index == 2){
        url = URL_YZ_anchor_room_delete_2;
    }else if (_index == 3){
        url = URL_YZ_anchor_quitMyRoom;
    }
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    if (_index == 3) {
        [dic setValue:_infoModel.room forKey:@"room"];
    }else{
        [dic setValue:_model.ID forKey:@"userid"];
        if (_index == 2 || _index == 1) {
            [dic setValue:[XTGlobalManager shareInstance].identification forKey:@"room"];
        }
    }
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",httpsUrl,url];
    [CustomRequest cus_request:urlStr withRequesType:HttpsRequestTypePost parameters:dic success:^(NSDictionary * _Nullable responseObjc) {
        NSLog(@"獲取列表信息index = 1:%@",responseObjc);
        if (YZ_success_back == 1) {
            self.infoBlock();
        }else {
            YZ_success_show;
        }
    } failure:^(NSError * _Nullable error) {

    }];
}



@end

效果圖大概是這樣子的

IMG_0071.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末窒朋,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子岂座,更是在濱河造成了極大的恐慌,老刑警劉巖椒涯,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件誉简,死亡現(xiàn)場離奇詭異碉就,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)闷串,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進(jìn)店門瓮钥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人烹吵,你說我怎么就攤上這事碉熄。” “怎么了肋拔?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵锈津,是天一觀的道長。 經(jīng)常有香客問我凉蜂,道長琼梆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任窿吩,我火速辦了婚禮茎杂,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘纫雁。我一直安慰自己煌往,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布先较。 她就那樣靜靜地躺著携冤,像睡著了一般悼粮。 火紅的嫁衣襯著肌膚如雪闲勺。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天扣猫,我揣著相機(jī)與錄音菜循,去河邊找鬼。 笑死申尤,一個(gè)胖子當(dāng)著我的面吹牛癌幕,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播昧穿,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼勺远,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了时鸵?” 一聲冷哼從身側(cè)響起胶逢,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤厅瞎,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后初坠,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體和簸,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年碟刺,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了锁保。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,013評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡半沽,死狀恐怖爽柒,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情抄囚,我是刑警寧澤霉赡,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站幔托,受9級特大地震影響穴亏,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜重挑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一嗓化、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧谬哀,春花似錦刺覆、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至篇梭,卻和暖如春氢橙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背恬偷。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工悍手, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人袍患。 一個(gè)月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓坦康,卻偏偏與公主長得像,于是被迫代替她去往敵國和親诡延。 傳聞我的和親對象是個(gè)殘疾皇子滞欠,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容