ios - How to set a max limit for an IBInspectable Int -


i using ibinspectable int in swift choose between 4 four shapes (0-3), possible in storyboard editor set value greater 3 , less 0, stops ibdesignable system working.

is possible set min , max limit of values can set in storyboard editor?

let shape_cross = 0 let shape_square = 1 let shape_circle = 2 let shape_triangle = 3  @ibinspectable var shapetype: int = 0 @ibinspectable var shapesize: cgfloat = 100.0 @ibinspectable var shapecolor: uicolor? 

there's no way limit user can input in storyboard. however, prevent invalid values being stored using computed property:

  @ibinspectable var shapetype: int {     set(newvalue) {       internalshapetype = min(newvalue, 3)     }     {       return internalshapetype     }   }    var internalshapetype: int = 0 

then use enum instead of constants represent different shape types internally.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -