美文网首页
iOS 点赞头像列表叠加效果

iOS 点赞头像列表叠加效果

作者: marlonxlj | 来源:发表于2019-12-17 01:50 被阅读0次

直接上效果图

72DB9100-E5C2-40A9-BDDA-98A5502A248A.png

swift int转cgfloat报错,进行转换:CGFloat

直接上代码

虽然实现很简单还是记录一下,方面后来人。

//
//  HYHotelResHeaderView.swift
//  HYTravel
//
//  Created by sweet on 2019/12/17.
//  Copyright © 2019 sweet. All rights reserved.
//

import UIKit

class HYHotelResHeaderView: UIView {

    var arrayIcon:NSArray?
    
    convenience init(frame:CGRect, withArray array: [Any]){
        self.init()
        arrayIcon = array as NSArray
        
        settingChildView()
    }
    
    private func settingChildView(){
        //宽高相等
        let w:Int = 28
        
        for i in 0..<arrayIcon!.count {
            let dic = arrayIcon![i] as! NSDictionary
            let urlPath = dic["icon"]
            let imgIcon = UIImageView.init()
            
            imgIcon.layer.masksToBounds = true
            imgIcon.layer.cornerRadius = 14
            
            //计算:CGFloat(w * i + i * margin)
            let margin = -5
            let X:CGFloat = CGFloat(w * i + i * margin)
            imgIcon.kf.setImage(with: URL.init(string: urlPath as! String))
            self.addSubview(imgIcon)
            
            imgIcon.snp.makeConstraints { (make) in
                make.top.equalTo(11)//根据view高度减去图片高度/2的结果,使用center效果不行
                make.left.equalTo(X)
                make.height.width.equalTo(CGFloat(w))  
            }
            
        }
        
    }
    
}

相关文章

网友评论

      本文标题:iOS 点赞头像列表叠加效果

      本文链接:https://www.haomeiwen.com/subject/icbjnctx.html