ReuseClass
示例
要运行示例项目,请先克隆仓库,然后在示例目录中运行pod install
。
要求
- iOS 10.0+
- Xcode 11+
- Swift 5.0+
安装
ReuseClass可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'ReuseClass'
初始化和用法
集成
将 ReuseClass 模块导入 ViewController.swift 文件
然后点击您添加的 UIView,进入身份检查器。将类设置为 ReuseClass。
在内部初始化 ReuseClass
class ViewController: UIViewController {
var objCatList = [CatList]()
var objCategoryList = [CategoryList]()
override func viewDidLoad() {
super.viewDidLoad()
}
//Category setup
@IBOutlet weak var customTableView: ReuseClass! {
didSet {
customTableView.delegate = self
customTableView.vCategoryItem = vCategoryItem
customTableView.isAdvisorVisible = false
//customTableView.tableCellHeight = 50 //set height of row, default height is 50
}
}
lazy var vCategoryItem: [CategoryItem] = {
setUpCategory()
let slices = objCatList.map({CategoryItem.init(itemname: $0.name , emoji: $0.emoji, avgPercent: $0.avgPercent, youPercent: $0.youPercent, monthlyOverSpendDollar: $0.monthlyOverSpendDollar)})
return slices
}()
func setUpCategory () {
let Itemone = CatList(emoji: "https://dl.dropboxusercontent.com/s/grmetj2iixvz253/Group%201320.png", name: "Restaurent", avgPercent: "0.26%", youPercent: "0.36%", monthlyOverSpendDollar: "76")
let Itemtwo = CatList(emoji: "https://dl.dropboxusercontent.com/s/rx8rh1uxhxrawx9/Group%201669.png", name: "Clothing", avgPercent: "0.27%", youPercent: "0.37%", monthlyOverSpendDollar: "76")
let Itemthree = CatList(emoji: "https://dl.dropboxusercontent.com/s/igoyutvhcf5hgdr/Group%201670.png", name: "Subscription", avgPercent: "0.28%", youPercent: "0.38%", monthlyOverSpendDollar: "76")
objCatList.append(Itemone)
objCatList.append(Itemtwo)
objCatList.append(Itemthree)
}
//Achievements
@IBOutlet weak var achivementTableView: AchievementProgressbar! {
didSet {
achivementTableView.vCategoryItem = vAchivementCategory
//achivementTableView.tableCellHeight = 50 //set height of row, default height is 50
}
}
lazy var vAchivementCategory: [AchivementItem] = {
setUpachievementCategory()
let objvAchivementCategory = objCategoryList.map({AchivementItem.init(itemname: $0.name, emoji: $0.emoji, max: $0.max, value: $0.value, outlineColor: $0.outlineColor, barColor: $0.barColor, backgroundColor: $0.backgroundColor, textColor: $0.textColor)})
return objvAchivementCategory
}()
func setUpachievementCategory () {
let Itemone = CategoryList(emoji: "https://dl.dropboxusercontent.com/s/zrw9oemgnp14afi/Balance%20%240.png", name: "Watch 30 ads + 100", max: "70", value: "35", outlineColor: "#2A3137", barColor:"#FDAEB6", backgroundColor: "#040D14", textColor: "#FFFFFF")
let Itemtwo = CategoryList(emoji: "https://dl.dropboxusercontent.com/s/zrw9oemgnp14afi/Balance%20%240.png", name: "Scan 20 Reciept + 200", max: "70", value: "30", outlineColor: "#2A3137", barColor:"#FDAEB6", backgroundColor: "#040D14", textColor: "#FFFFFF")
objCategoryList.append(Itemone)
objCategoryList.append(Itemtwo)
}
}
现在将这些与出口相连接,并连接到名为 customTableView 的出口,用于“消费”类别列表和卡片,以及 achievementsTableView 用于成就进度条。
我们想让视图控制器实现 ReuseClass 代理协议,在此阶段 ViewController.swift 应该看起来如下
//MARK:- ReuseClassdelegate
extension ViewController : ReuseClassdelegate{
func onCardClosedClick(_ Vcustomclass: ReuseClass) {
print("Card close")
}
}
作者
vandanapansuria, [email protected]
许可证
ReuseClass 遵循 MIT 许可协议。更多信息请查看 LICENSE 文件。