I've implemented a Shuffle package(https://cocoapods.org/pods/Shuffle-iOS), my main target is to create tinder like swap animation, Shuffle package really helped me, but I can only add images and swap them, what I want to do is to add a text label, and configure them with array which I've already created, but the documentation doesn't provide how to do that, I'm new to IOS, I understand some things, but some I don't, I tried to give property with string, created array and configured with delegates, but I can't see my Strings on view here's code below:
let cardImages = [
UIImage(named: "cardImage1"),
UIImage(named: "cardImage2"),
UIImage(named: "cardImage3")
]
let texts = [
"Hello","World","My"
]
// gave function below string property
func card(fromImage image: UIImage, fromText text:String) -> SwipeCard {
let card = SwipeCard()
card.swipeDirections = [.left, .right]
card.content = UIImageView(image: image)
let textLabel = UILabel() //created label here
let leftOverlay = UIView()
leftOverlay.backgroundColor = .green
let rightOverlay = UIView()
rightOverlay.backgroundColor = .red
card.setOverlays([.left: leftOverlay, .right: rightOverlay])
return card
}
func cardStack(_ cardStack: SwipeCardStack, cardForIndexAt index: Int) -> SwipeCard {
return card(fromImage: cardImages[index]!, fromText: texts[index]) // configured card here
}
If you have any addition question, feel free to comment.
CodePudding user response:
Yes you can add text, labels, buttons, etc in shuffle
here is a code for that
func card1(fromJob Job: Job, index: String) -> SwipeCard {
let card = SwipeCard()
card.swipeDirections = [.left, .right, .up]
card.layer.cornerRadius = 12
card.layer.shadowOffset = CGSize.zero
card.layer.shadowOpacity = 1.0
card.layer.shadowRadius = 6.0
card.layer.masksToBounds = false
card.layer.borderWidth = 2
let view_bg = UIView(frame: CGRect(x: 16, y: 60, width: self.view.frame.size.width - 32, height: self.view.frame.height * 0.75))
card.content = view_bg
view_bg.layer.cornerRadius = 12
view_bg.clipsToBounds = true
DispatchQueue.main.asyncAfter(deadline: .now() 0.1) { [self] in
let view_bg1 = UIView(frame: CGRect(x: 0, y: 0, width: view_bg.frame.size.width, height: view_bg.frame.size.height))
card.content?.addSubview(view_bg1)
let img_card_type = UIImageView(frame: CGRect.zero)
img_card_type.contentMode = .scaleAspectFit
img_card_type.translatesAutoresizingMaskIntoConstraints = false
img_card_type.isHidden = true
view_bg1.addSubview(img_card_type)
img_card_type.centerXAnchor.constraint(equalToSystemSpacingAfter: view_bg1.centerXAnchor, multiplier: 1).isActive = true
img_card_type.topAnchor.constraint(equalTo: view_bg1.topAnchor, constant: 12).isActive = true
img_card_type.widthAnchor.constraint(equalToConstant: 100).isActive = true
img_card_type.heightAnchor.constraint(equalToConstant: 35).isActive = true
let img_comapny = UIImageView(frame: CGRect(x: 24, y: 24, width: 100, height: 100))
img_comapny.image = UIImage(named: "icon_emploimi")
img_comapny.translatesAutoresizingMaskIntoConstraints = false
img_comapny.layer.cornerRadius = 50
img_comapny.layer.shadowOffset = CGSize.zero
img_comapny.layer.shadowOpacity = 1.0
img_comapny.layer.shadowRadius = 6.0
img_comapny.layer.masksToBounds = false
img_comapny.clipsToBounds = true
view_bg1.addSubview(img_comapny)
img_comapny.topAnchor.constraint(equalTo: img_card_type.bottomAnchor, constant: 0).isActive = true
img_comapny.leadingAnchor.constraint(equalTo: view_bg1.leadingAnchor, constant: 24).isActive = true
img_comapny.heightAnchor.constraint(equalToConstant: 100).isActive = true
img_comapny.widthAnchor.constraint(equalToConstant: 100).isActive = true
let lbl_company_name = UILabel(frame: CGRect.zero)
lbl_company_name.translatesAutoresizingMaskIntoConstraints = false
lbl_company_name.numberOfLines = 3
lbl_company_name.font = AppFont.getBold(forStyle: .title3)
view_bg1.addSubview(lbl_company_name)
lbl_company_name.leadingAnchor.constraint(equalTo: img_comapny.trailingAnchor, constant: 24).isActive = true
lbl_company_name.trailingAnchor.constraint(equalTo: view_bg1.trailingAnchor, constant: -24).isActive = true
lbl_company_name.centerYAnchor.constraint(equalToSystemSpacingBelow: img_comapny.centerYAnchor, multiplier: 1).isActive = true
let job_title = UILabel(frame: CGRect.zero)
job_title.text = Job.title //"iOS Developer"
job_title.translatesAutoresizingMaskIntoConstraints = false
job_title.numberOfLines = 2
job_title.font = AppFont.getBold(forStyle: .title3)
view_bg1.addSubview(job_title)
job_title.topAnchor.constraint(equalTo: img_comapny.bottomAnchor, constant: 32).isActive = true
job_title.leadingAnchor.constraint(equalTo: view_bg1.leadingAnchor, constant: 24).isActive = true
job_title.trailingAnchor.constraint(equalTo: view_bg1.trailingAnchor, constant: -24).isActive = true
}
let leftOverlay = UIImageView()
let img_dislike = UIImageView(frame: CGRect(x: view_bg.frame.size.width - 132, y: 32, width: 100, height: 100))
img_dislike.image = UIImage(named: "ic_dislike")
leftOverlay.addSubview(img_dislike)
let rightOverlay = UIView()
let img_like = UIImageView(frame: CGRect(x: 32, y: 32, width: 100, height: 100))
img_like.image = UIImage(named: "ic_like")
rightOverlay.addSubview(img_like)
let upOverlay = UIView()
let img_saved = UIImageView(frame: CGRect(x: (view_bg.frame.size.width - 100)/2, y: (view_bg.frame.size.height)/2, width: 100, height: 100))
img_saved.image = UIImage(named: "ic_save")
upOverlay.addSubview(img_saved)
card.setOverlays([.left: leftOverlay, .right: rightOverlay, .up: upOverlay])
return card
}
You can add view inside SwipeCard through the program and add labels and text in that easily.
