EMTNeumorphicView 1.0.4

EMTNeumorphicView 1.0.4

Hironobu Kimura 维护。



  • hirokimu

EMTNeumorphicView

具有 Neumorphism 风格设计的 UIKit 视图。

License Language Pod Version Carthage Compatible Swift Package Manager compatible

安装

您可以通过 CocoaPods / Carthage / SwiftPM 获取 EMTNeumorphicView。要通过 CocoaPods 安装它,请简单地将其添加到您的 Podfile 中以下行

pod 'EMTNeumorphicView'

要运行示例项目,请先从仓库克隆,然后在 Example 目录中运行 pod install

使用

您可以使用 EMTNeumorphicView / EMTNeumorphicButton / EMTNeumorphicTableCell。每个视图都是 UIView / UIButton/ UITableViewCell 的子类。

EMTNeumorphicView

    let myView = EMTNeumorphicView()
    myView.neumorphicLayer?.elementBackgroundColor = view.backgroundColor?.cgColor
    myView.neumorphicLayer?.cornerRadius = 24
    // set convex or concave.
    myView.neumorphicLayer?.depthType = .concave
    // set elementDepth (corresponds to shadowRadius). Default is 5
    myView.neumorphicLayer?.elementDepth = 7

EMTNeumorphicButton

基本上等同于EMTNeumorphicView。

    let button = EMTNeumorphicButton(type: .custom)
    button.setImage(UIImage(named: "heart-outline"), for: .normal)
    button.setImage(UIImage(named: "heart-solid"), for: .selected)
    button.contentVerticalAlignment = .fill
    button.contentHorizontalAlignment = .fill
    button.imageEdgeInsets = UIEdgeInsets(top: 26, left: 24, bottom: 22, right: 24)
    button.addTarget(self, action: #selector(tapped(_:)), for: .touchUpInside)
    
    button.neumorphicLayer?.elementBackgroundColor = view.backgroundColor?.cgColor

    @objc func tapped(_ button: EMTNeumorphicButton) {
        // isSelected property changes neumorphicLayer?.depthType automatically
        button.isSelected = !button.isSelected
    }

EMTNeumorphicTableCell

不要在同一部分中使用凸面和凹面一起。这会导致视觉效果不佳。

    // change neumorphicLayer?.cornerType according to its row position
    var type: EMTNeumorphicLayerCornerType = .all
    if rowCount > 1 {
        if indexPath.row == 0 {
            type = .topRow
        }
        else if indexPath.row == rowCount - 1 {
            type = .bottomRow
        }
        else {
            type = .middleRow
        }
    }
    let cellId = String(format: "cell%d", type.rawValue)
    var cell = tableView.dequeueReusableCell(withIdentifier: cellId)
    if cell == nil {
        cell = EMTNeumorphicTableCell(style: .default, reuseIdentifier: cellId)
    }
    if let cell = cell as? EMTNeumorphicTableCell {
        cell.neumorphicLayer?.cornerType = type
        cell.neumorphicLayer?.elementBackgroundColor = view.backgroundColor?.cgColor
    }

其他属性

    // Default is 1.
    myView.neumorphicLayer?.lightShadowOpacity = 1

    // Default is 0.3.
    myView.neumorphicLayer?.darkShadowOpacity = 1

    // Optional. if it is nil (default), elementBackgroundColor will be used as element color.
    myView.neumorphicLayer?.elementColor = UIColor.red.cgColor
    
    // Adding a thin border on the edge of the element.
    myView.neumorphicLayer?.edged = true

要求

Swift 5 / iOS 13

许可协议

EMTNeumorphicView遵循MIT许可协议。有关更多信息,请参阅LICENSE文件。