I have a UIButton with title and image onto the right of the title. But i wanna draw the image using paintcode app rather than using image in assets. How can i do it?
Asked
Active
Viewed 194 times
0
-
You will need a custom UIButton to do that as PaintCode does not generate a UIImage. – Tamás Sengel Apr 04 '18 at 15:03
-
@the4kman, i do have a custom button but if i add the paintCodeApp generated code in override func draw(_ rect: CGRect) {}, it just draws the within the whole button. – j.krissa Apr 04 '18 at 15:06
1 Answers
2
You could either create an reusable widget based on a .xib
file, which would draw everything you need, for example:
Reusable widget (loaded from a .xib)
_____________________________________________
| UIView |
| ___________________________________ |
| | Button | Image (from PaintCode) | |
| |_________|_________________________| |
|_____________________________________________|
... or do everything inside PaintCode itself (the image AND the text), like:
... which would result in the following:
You could even use @IBInspectable
to set the text of the button directly in 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)
}
}
Since you are already using PaintCode, I would stick to it and do everything you could there.
Take a look at PaintCode's documentation on using variables.
And here's the Xcode project: https://github.com/backslash-f/paintcode-tests

backslash-f
- 7,923
- 7
- 52
- 80