直接上效果图
72DB9100-E5C2-40A9-BDDA-98A5502A248A.pngswift 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))
}
}
}
}
网友评论