Search code examples
swiftdrawrectuitabbaritempaintcode

Drawing from PaintCode StyleKit to UITabBarItem


I need to use a PaintCode StyleKit in a UITabBarItem. If I was working with a UIButton, I would simply use these lines of code:

override func drawRect(rect: CGRect) {
    MyStyleKit.drawButton(self.frame)
}

But if I have to work with a UITabBarItem (which doesn't have a drawRect function), I'm not able to draw the object realized in PaintCode.


Solution

  • As you said, UITabBar doesn't have a drawRect function, and can't directly draw with the code PaintCode generated. However, PaintCode has a way to export code that returns a UIImage instead. It's described in their documentation:

    The "StyleKit" popup button specifies what code should be generated for the selected canvas.

    By default, the drawing method is generated. However, you can also choose "Image Method", which will generate a method that returns an UIImage with the content of your canvas.

    This UIImage is drawn by code when the method is called.

    If you select the "Image" or "Drawing & Image" method from this popup, you'll have a function in your StyleKit that exports a UIImage, which you can then set on your tab bar item when it's created.