Search code examples
expressionpaintcode

PaintCode expression for dynamic stroke width based on frame


I've got a bezier with a stroke which is contained within a frame. My bezier resizes dynamically along with the frame very nicely, but the stroke width is static which makes it look bad at small sizes. (Notice how the stroke isn't proportional on the small star below.)

enter image description here

My first thought was to make the stroke width (normally 5) an expression that was based something like 5.0*(frame.width/standardwidth) but I'm not allowed to reference the frame variable.

How can I make an expression to calculate a stroke width based on the frame width? Or somehow make the stroke width dynamically sized like the rest of the elements within the frame?


Solution

  • For me this works out of the box. That is:

    "...somehow make the stroke width dynamically sized like the rest of the elements within the frame"

    Versions:

    • PaintCode 3.4 (34000)
    • Xcode 9.4.1 (9F2000)
    • Swift 4.1.2

    PaintCode Setup

    PaintCode Setup

    Custom View

    import Foundation
    import UIKit
    
    @IBDesignable class StarView: UIView {
    
        override func draw(_ rect: CGRect) {
            StyleKit.drawStarIcon(frame: rect)
        }
    }
    

    Final Result

    Final Result

    GitHub

    https://github.com/backslash-f/paintcode-tests