测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | BSD |
发布日期上一版本发布日期 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Darkkrye 维护。
我正在尝试做更多的代码覆盖率,但在测试带有 xib 文件的代码时我遇到了一些问题。我正在寻找如何做它,但同时在,我不能测试大量的代码。图形功能也是同样的情况。
DKDetailsParallax 是可可可可aps上可用的框架。
要安装,请将此行添加到您的 Podfile 中
pod 'DKDetailsParallax'
默认情况下,框架包含一个 ViewController 供继承。这个 ViewController 包含了实现视差头部和 UITableView 的所有基本代码。
框架还包含了一些您可以用在 UITableView 中的单元格。其他的一些将会逐步添加。您还可以检查单元格的创建方式来自定义单元格。
单元格按主题分组
第一步,您必须创建一个新的 UIViewController
,导入 DKDetailsParallax
并使其继承自 DKDetailsParallaxViewController
。然后通过添加您的代码和变量来重写默认方法。不要忘记在 viewDidLoad
方法中最后一两行代码。
import DKDetailsParallax
class MyViewController: DKDetailsParallaxViewController {
var myObject: MyObject
override func viewDidLoad() {
super.viewDidLoad()
// Your code to retrieve or make something with you data.
// ...
myObject.retrieveInformation()
// ...
// Don't forget to set headerImage and call setupController function at the end of the viewDidLoad. If you are making web calls then add these two lines in the main Thread
self.setHeaderImage(image: myObject.imageBanner)
self.setupController()
}
}
现在您可以创建您控制器的新实例以显示它
let myObject = self.myobjects[indexPath.row]
let vc = MyViewController(primaryColor: self.primaryColor, secondaryColor: nil, title: myObject.title, headerImage: nil, idObject: nil, object: myObject, withBlurredNavbar: true)
self.present(vc, animated: true, completion: nil)
下一步是创建一个新的扩展以覆盖 UITableView
方法。在里面,您可以按照您的需要使用单元格。
extension MyViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 9
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
var roundedDetailsProfile: RoundedDetailsRectangleProfile! = tableView.dequeueReusableCell(withIdentifier: "RoundedDetailsRectangleProfile") as? RoundedDetailsRectangleProfile
if roundedDetailsProfile == nil {
roundedDetailsProfile = RoundedDetailsRectangleProfile.detailsProfile(withPrimaryColor: self.primaryColor, andSecondaryColor: nil)
}
roundedDetailsProfile.rectangleImageView.image = myObject.image
roundedDetailsProfile.titleLabel.text = "\(myObject.title) - \(myObject.information)"
roundedDetailsProfile.subtitleLabel.text = "\(myObject.anotherInformation)"
roundedDetailsProfile.delegate = self
return roundedDetailsProfile
case 1:
var roundedDetailsProfile: RoundedDetailsProfile! = tableView.dequeueReusableCell(withIdentifier: "RoundedDetailsProfile") as? RoundedDetailsProfile
if roundedDetailsProfile == nil {
roundedDetailsProfile = RoundedDetailsProfile.detailsProfile(withPrimaryColor: self.primaryColor, andSecondaryColor: nil)
}
roundedDetailsProfile.squareImageView.image = myObject.image
roundedDetailsProfile.titleLabel.text = "\(myObject.title) - \(myObject.information)"
roundedDetailsProfile.subtitleLabel.text = "\(myObject.anotherInformation)"
roundedDetailsProfile.delegate = self
return roundedDetailsProfile
case 2:
var flatSimpleCell: FlatLightSimpleLabelCell! = tableView.dequeueReusableCell(withIdentifier: "FlatLightSimpleLabelCell") as? FlatLightSimpleLabelCell
if flatSimpleCell == nil {
flatSimpleCell = FlatLightSimpleLabelCell.simpleCell(withPrimaryColor: self.primaryColor, andSecondaryColor: nil)
}
flatSimpleCell.contentLabel.text = "DARK SIDE"
return flatSimpleCell
case 3:
var flatDescCell: FlatLightSimpleDescriptionCell! = tableView.dequeueReusableCell(withIdentifier: "FlatLightSimpleDescriptionCell") as? FlatLightSimpleDescriptionCell
if flatDescCell == nil {
flatDescCell = FlatLightSimpleDescriptionCell.simpleDescriptionCell(withPrimaryColor: nil, andSecondaryColor: nil)
}
flatDescCell.setTitleText(text: "full name")
flatDescCell.contentLabel.text = "Anakin Skywalker"
return flatDescCell
case 4:
var switchCell: FlatLightSwitchCell! = tableView.dequeueReusableCell(withIdentifier: "FlatLightSwitchCell") as? FlatLightSwitchCell
if switchCell == nil {
switchCell = FlatLightSwitchCell.switchCell(withPrimaryColor: nil, andSecondaryColor: nil)
}
switchCell.setTitleText(text: "Sexe")
switchCell.switchView.leftText = "Male"
switchCell.switchView.rightText = "Female"
switchCell.switchView.rightSelected = false
switchCell.delegate = self
return switchCell
case 5:
var flatSimpleCell: FlatDarkSimpleLabelCell! = tableView.dequeueReusableCell(withIdentifier: "FlatDarkSimpleLabelCell") as? FlatDarkSimpleLabelCell
if flatSimpleCell == nil {
flatSimpleCell = FlatDarkSimpleLabelCell.simpleCell(withPrimaryColor: self.primaryColor, andSecondaryColor: nil)
}
flatSimpleCell.contentLabel.text = "DARK SIDE"
return flatSimpleCell
case 6:
var flatDescCell: FlatDarkSimpleDescriptionCell! = tableView.dequeueReusableCell(withIdentifier: "FlatDarkSimpleDescriptionCell") as? FlatDarkSimpleDescriptionCell
if flatDescCell == nil {
flatDescCell = FlatDarkSimpleDescriptionCell.simpleDescriptionCell(withPrimaryColor: nil, andSecondaryColor: nil)
}
flatDescCell.setTitleText(text: "full name")
flatDescCell.contentLabel.text = "Anakin Skywalker"
return flatDescCell
case 7:
var switchCell: FlatDarkSwitchCell! = tableView.dequeueReusableCell(withIdentifier: "FlatDarkSwitchCell") as? FlatDarkSwitchCell
if switchCell == nil {
switchCell = FlatDarkSwitchCell.switchCell(withPrimaryColor: nil, andSecondaryColor: nil)
}
switchCell.setTitleText(text: "Gender")
switchCell.switchView.leftText = "Male"
switchCell.switchView.rightText = "Female"
switchCell.switchView.rightSelected = false
switchCell.delegate = self
return switchCell
case 8:
var buttonCell: RoundedButtonCell! = tableView.dequeueReusableCell(withIdentifier: "RoundedButtonCell") as? RoundedButtonCell
if buttonCell == nil {
buttonCell = RoundedButtonCell.buttonCell(withPrimaryColor: self.primaryColor, andSecondaryColor: nil)
}
buttonCell.button.setTitle("\(myObject.actionName)", for: .normal)
buttonCell.delegate = self
return buttonCell
default:
return UITableViewCell()
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.row {
case 0:
return RoundedDetailsRectangleProfile.defaultHeight
case 1:
return RoundedDetailsProfile.defaultHeight
case 2:
return FlatLightSimpleLabelCell.defaultHeight
case 3:
return FlatLightSimpleDescriptionCell.defaultHeight
case 4:
return FlatLightSwitchCell.defaultHeight
case 5:
return FlatDarkSimpleLabelCell.defaultHeight
case 6:
return FlatDarkSimpleDescriptionCell.defaultHeight
case 7:
return FlatDarkSwitchCell.defaultHeight
case 8:
return RoundedButtonCell.defaultHeight
default:
return 44
}
}
}
最后一步,创建一个新的扩展以符合单元格代理的规范。因为您不会使用所有的单元格,所有的回调函数都是可选的。
extension MyViewController: DKDetailsParallaxCellDelegate {
// MARK: - Rounded Theme
// MARK: RoundedDetailsProfileCell
func roundedDetailsProfileCellCallback(cell: RoundedDetailsProfileCell, forCircleButton: UIButton) {
// Add Your Code
}
func roundedDetailsProfileCellCallback(cell: RoundedDetailsProfileCell, forOutlinedButton: UIButton) {
// Add Your Code
}
func roundedDetailsProfileCellCallback(cell: RoundedDetailsProfileCell, forPlainButton: UIButton) {
// Add Your Code
}
// MARK: RoundedDetailsRectangleProfileCell
func roundedDetailsRectangleProfileCellCallback(cell: RoundedDetailsRectangleProfileCell, forCircleButton: UIButton) {
// Add Your Code
}
func roundedDetailsRectangleProfileCellCallback(cell: RoundedDetailsRectangleProfileCell, forOutlinedButton: UIButton) {
// Add Your Code
}
func roundedDetailsRectangleProfileCellCallback(cell: RoundedDetailsRectangleProfileCell, forPlainButton: UIButton) {
// Add Your Code
}
// MARK: RoundedButtonCell
func roundedButtonCellCallback(cell: RoundedButtonCell, forButton: UIButton) {
// Add Your Code
}
/* ------------------------------------------------------------------------------------------------------------------------------------------ */
// MARK: - Flat Light Theme
// FlatLightSwitchCell
func flatLightSwitchCellCallback(cell: FlatLightSwitchCell, onSwitchUpdate: Switch, toTheValue: String) {
// Add Your Code
}
/* ------------------------------------------------------------------------------------------------------------------------------------------ */
// MARK: - Flat Light Theme
// FlatDarkSwitchCell
func flatDarkSwitchCellCallback(cell: FlatDarkSwitchCell, onSwitchUpdate: Switch, toTheValue: String) {
// Add Your Code
}
}
最终步骤:享受吧!
默认情况下,该框架附带一些资源,例如 .xib、jpg 或 png 图片和字体等。
如果您想使用它,不能像默认那样使用,因为框架位于另一个包中。
要获取访问权限,您可以通过调用 DKDetailsParallax 函数来检索正确的包。
public static func bundle() -> Bundle?
然后您可以这样使用它。
UIImage(named: "defaultProfile", in: DKDetailsParallax.bundle(), compatibleWith: nil)
当前稳定版本 2.2.0
我在单元格中使用 T-Pham/Switch 库的开关,所以感谢他。