我想在刷卡时增加标签数量。在我的应用程序中,我正在从模型加载卡片数据,因此根据模型中的数据,将显示堆叠在一起的卡片数量,我已使用uiview xib,并且卡片中有一个标签,上面写着“ 1 20英寸表示它是第一张卡片,现在我刷卡时,我希望它是20张卡片中的2张,依此类推。我已经使用ZLSwipeable视图库进行刷卡,但是没有答案。
我的刷卡功能
class FlipCardVC: UIViewController {
var wordsData = [ModelResult]()
var cardId = Int()
@IBOutlet weak var SwipeCardOuterView: UIView!
var swipeableView: ZLSwipeableView!
var colorIndex = 0
var loadCardsFromXib = false
}
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
constrain(SwipeCardOuterView, view) { view1, view2 in
view1.left == view2.left
view1.top == view2.top
view1.width == view.bounds.width
view1.height == view.bounds.height
}
}
override func viewDidLayoutSubviews()
{
super.viewDidLayoutSubviews()
if let swview = swipeableView
{
swview.nextView = {
return self.nextCardView()
}
}
}
func nextCardView() -> UIView?
{
let arrayData = wordsData
if (self.colorIndex >= arrayData.count)
{
return nil
}
let cardView = CardView(frame: swipeableView.bounds)
if loadCardsFromXib
{
let contentView = Bundle.main.loadNibNamed("CardContentView", owner: self, options: nil)?.first! as! CardView
contentView.superVC = self
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.backgroundColor = cardView.backgroundColor
cardView.addSubview(contentView)
let data = arrayData[(self.colorIndex)] as ModelResult
contentView.wordModel = data
let savedValue = UserDefaults.standard.bool(forKey: "isLangChanged")
tempLangChanged = savedValue
if tempLangChanged == false
{
if let spanishName = data.cardWordEnglish, spanishName.count != 0
{
contentView.wordSpanish.text = spanishName
print(spanishName)
}
}
else
{
if let dict = data.cardWordImage, dict.count != 0
{
let url = WS_wordIconUrl + dict
contentView.wordImage.kf.indicatorType = .activity
contentView.wordImage.kf.setImage(with: URL(string: url))
}
if let spanishName = data.cardWordSpanish, spanishName.count != 0
{
contentView.wordSpanish.text = spanishName
print(spanishName)
}
}
contentView.soundBtn.addTarget(self, action:#selector(self.soundBtn(sender:)), for: .touchUpInside)
contentView.hideCard.addTarget(self, action:#selector(self.hideCard(sender:)), for: .touchUpInside)
contentView.soundBtn.tag = self.colorIndex
contentView.hideCard.tag = self.colorIndex
cardView.tag = self.colorIndex
constrain(contentView, cardView) { view1, view2 in
view1.left == view2.left
view1.top == view2.top
view1.width == cardView.bounds.width
view1.height == cardView.bounds.height
}
}
colorIndex += 1
return cardView
}
//MARK: API Parsing for deck words data
func WS_GetWords()
{
if ApiUtillity.sharedInstance.isReachable()
{
ApiUtillity.sharedInstance.StartProgress(view: self.view)
let url = "\(WS_GetWordsAPI)/\(cardId)"
APIClient<ModelBaseGetWordsData>().API_GET(Url: url, Params: [:], Authentication: true, Progress: true, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (modelResponse) in
if(modelResponse.success == true)
{
ApiUtillity.sharedInstance.StopProgress(view: self.view)
self.colorIndex = 0
self.wordsData.removeAll()
if let array = modelResponse.result, array.count != 0
{
for data in array
{
self.wordsData.append(data)
}
self.cardInit()
}
else
{
self.colorIndex = 0
self.wordsData.removeAll()
DispatchQueue.main.asyncAfter(deadline: .now(), execute:
{
if self.swipeableView != nil
{
self.swipeableView.removeFromSuperview()
}
self.cardInit()
})
}
}
else
{
self.showToast(message: modelResponse.message!)
ApiUtillity.sharedInstance.StopProgress(view: self.view)
}
// self.cardSwiper.reloadData()
if self.wordsData.count == 0
{
self.setNoDataMessage(message: modelResponse.message)
}
}) { (failed) in
self.showToast(message: failed.localizedDescription)
ApiUtillity.sharedInstance.StopProgress(view: self.view)
}
}
else
{
self.showToast(message: "No internet connection...")
}
}