在随机包中添加文本
add text in shuffle package
我已经实现了一个 Shuffle 包(https://cocoapods.org/pods/Shuffle-iOS),我的主要目标是创建像交换动画这样的 tinder,Shuffle 包对我很有帮助,但我只能添加图像并交换它们,我想要什么要做的是添加一个文本标签,并用我已经创建的数组配置它们,但是文档没有提供如何做到这一点,我是 IOS 的新手,我了解一些事情,但是有些我不知道,我试图给 属性 字符串,创建数组并配置委托,但我看不到我的字符串,下面是代码:
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
}
如有任何补充问题,欢迎留言。
是的,您可以在随机播放中添加文本、标签、按钮等
这是一个代码
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
}
您可以通过该程序在 SwipeCard 中添加视图,并在其中轻松添加标签和文本。
我已经实现了一个 Shuffle 包(https://cocoapods.org/pods/Shuffle-iOS),我的主要目标是创建像交换动画这样的 tinder,Shuffle 包对我很有帮助,但我只能添加图像并交换它们,我想要什么要做的是添加一个文本标签,并用我已经创建的数组配置它们,但是文档没有提供如何做到这一点,我是 IOS 的新手,我了解一些事情,但是有些我不知道,我试图给 属性 字符串,创建数组并配置委托,但我看不到我的字符串,下面是代码:
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
}
如有任何补充问题,欢迎留言。
是的,您可以在随机播放中添加文本、标签、按钮等
这是一个代码
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
}
您可以通过该程序在 SwipeCard 中添加视图,并在其中轻松添加标签和文本。