2

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.

Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43
Fabio Cenni
  • 841
  • 3
  • 16
  • 30
  • I'm running into a similar problem when using PaintCode-generated icons in a UITabBarItem. My StyleKit was already generating UIImages, but they all show up huge in the Tab Bar. Is that something you've run into, or might have some idea about how to handle? – Stoph Aug 02 '16 at 15:06
  • 1
    Did you use frame tools for to make a frame around your i con in paintcode? – Fabio Cenni Aug 02 '16 at 16:28
  • Ahh, that was the clue I needed! Thanks! Now I have things resizing nicely. – Stoph Aug 02 '16 at 19:14

1 Answers1

3

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.

Cocoatype
  • 2,572
  • 25
  • 42
  • Ok guy, I read the documentation shortly after asking the question. And now all work!!! Thanks a lot! only one last question: in code export window whats the differences between all four cap insets parameter? and what are the differences between automatic original and template rendering mode? – Fabio Cenni Aug 01 '16 at 12:31
  • 1
    First question: no insets vs. horizontal vs. vertical vs. both. Second question: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/c/tdef/UIImageRenderingMode – Cocoatype Aug 01 '16 at 12:37