UIButton 标题 + 使用 Paintcode 应用程序的图像

UIButton title + image using Paintcode app

我有一个 UIButton,标题和图像位于标题的右侧。但我想使用 paintcode 应用程序绘制图像,而不是在资产中使用图像。我该怎么做?

您可以根据 .xib 文件创建一个可重复使用的小部件,它将绘制您需要的所有内容,例如:

Reusable widget (loaded from a .xib)

 _____________________________________________
| UIView                                      | 
|     ___________________________________     |
|    | Button  |  Image (from PaintCode) |    |
|    |_________|_________________________|    |
|_____________________________________________|

... 或者在 PaintCode 本身(图像和文本)中执行所有操作,例如:

... 结果如下:

您甚至可以使用 @IBInspectable 直接在 Interface Builder 中设置按钮的文本:

import Foundation
import UIKit

@IBDesignable class TextButton: UIButton {

    // MARK: Properties

    // The button's text can be set in Interface Builder.
    @IBInspectable var text: String = "HelloWorld!" {
        didSet {
            setNeedsDisplay() // Forces PaintCode to redraw.
        }
    }

    override var isHighlighted: Bool {
        didSet {
            setNeedsDisplay()
        }
    }

    override var isSelected: Bool {
        didSet {
            setNeedsDisplay()
        }
    }

    override var isEnabled: Bool {
        didSet {
            setNeedsDisplay()
        }
    }

    // MARK: Lifecycle

    override func draw(_ rect: CGRect) {
        StyleKit.drawTextButton(frame: rect, buttonLabelText: text)
    }
}

既然你已经在使用 PaintCode,我会坚持下去,尽你所能。

Take a look at PaintCode's documentation on using variables.

And here's the Xcode project: https://github.com/backslash-f/paintcode-tests