Attributes - Tai-Kimura/SwiftJsonUI GitHub Wiki
Common Attributes
These attributes are available for all view types in SwiftJsonUI.
Platform Support
- β UIKit: Full support for all attributes
- β SwiftUI: Most attributes supported (see individual notes)
- β Jetpack Compose: Core attributes supported with modifiers
- β
Android XML: Attributes mapped to Android view attributes
- See KotlinJsonUI XML Support for detailed mappings
Attribute Reference
| attribute name | UIKit | SwiftUI | XML | type in json | details | remarks |
|---|---|---|---|---|---|---|
| id | β | β | β | string | ID for the view. Should be unique within the view file including 'include' and 'style' files | |
| type | β | β | β | string | Name of the view type. Pre-defined types listed in View Types | |
| include | β | β | β | string | File name to include | |
| style | β | β | β | string | Style file name to apply | |
| propertyName | β | β | β | string | Alternative property name for binding | UIKit only |
| binding | β | β | β | string/dict | Data binding key. Chain with '.' like 'teacher.student.name' | UIKit only |
| tag | β | β | β | integer | View tag for identification | UIKit only |
| visibility | β | β | β | string | View visibility: visible, invisible, gone. Default: visible | |
| shadow | β | β | β | string/dict | Shadow configuration. String: "color|offsetX|offsetY|opacity|radius" or dict with keys | |
| background | β | β | β | string | Background color (hex string e.g. #000000) | |
| tapBackground | β | β | β | string | Background color when tapped | |
| userInteractionEnabled | β | β | β | boolean | Enable user interaction | |
| cornerRadius | β | β | β | float | Corner radius | |
| borderColor | β | β | β | string | Border color | |
| borderWidth | β | β | β | float | Border width | |
| clipToBounds | β | β | β | boolean | Clip content to bounds | |
| hidden | β | β | β | boolean | Hide view | |
| alpha | β | β | β | float | View opacity (0.0 to 1.0) | |
| rect | β | β | β | array | Direct frame [x, y, width, height]. Disables auto layout | UIKit only |
| indexBelow | β | β | β | string | Insert below specified view ID | |
| indexAbove | β | β | β | string | Insert above specified view ID | |
| paddings | β | β | β | array | Padding array [all] or [v,h] or [top,h,bottom] or [top,left,bottom,right] | |
| paddingLeft | β | β | β | float | Left padding | |
| paddingRight | β | β | β | float | Right padding | |
| paddingTop | β | β | β | float | Top padding | |
| paddingBottom | β | β | β | float | Bottom padding | |
| margins | β | β | β | array | Margin array [all] or [v,h] or [top,h,bottom] or [top,left,bottom,right] | |
| leftMargin | β | β | β | float | Left margin | |
| rightMargin | β | β | β | float | Right margin | |
| topMargin | β | β | β | float | Top margin | |
| bottomMargin | β | β | β | float | Bottom margin | |
| minLeftMargin | β | β | β | float | Minimum left margin | UIKit only |
| minRightMargin | β | β | β | float | Minimum right margin | UIKit only |
| minTopMargin | β | β | β | float | Minimum top margin | UIKit only |
| minBottomMargin | β | β | β | float | Minimum bottom margin | UIKit only |
| maxLeftMargin | β | β | β | float | Maximum left margin | UIKit only |
| maxRightMargin | β | β | β | float | Maximum right margin | UIKit only |
| maxTopMargin | β | β | β | float | Maximum top margin | UIKit only |
| maxBottomMargin | β | β | β | float | Maximum bottom margin | UIKit only |
| centerInParent | β | β | β | boolean | Center view in parent | |
| centerVertical | β | β | β | boolean | Center vertically in parent | |
| centerHorizontal | β | β | β | boolean | Center horizontally in parent | |
| alignTop | β | β | β | boolean | Align to top of parent | |
| alignBottom | β | β | β | boolean | Align to bottom of parent | |
| alignLeft | β | β | β | boolean | Align to left of parent | |
| alignRight | β | β | β | boolean | Align to right of parent | |
| alignTopOfView | β | β | β | string | Position above specified view ID | |
| alignBottomOfView | β | β | β | string | Position below specified view ID | |
| alignLeftOfView | β | β | β | string | Position to left of specified view ID | |
| alignRightOfView | β | β | β | string | Position to right of specified view ID | |
| alignTopView | β | β | β | string | Align top edge with specified view | |
| alignBottomView | β | β | β | string | Align bottom edge with specified view | |
| alignLeftView | β | β | β | string | Align left edge with specified view | |
| alignRightView | β | β | β | string | Align right edge with specified view | |
| alignCenterVerticalView | β | β | β | string | Align vertical center with specified view | |
| alignCenterHorizontalView | β | β | β | string | Align horizontal center with specified view | |
| width | β | β | β | float/string | Required. Width: matchParent, wrapContent, or number | |
| height | β | β | β | float/string | Required. Height: matchParent, wrapContent, or number | |
| minWidth | β | β | β | float | Minimum width | |
| minHeight | β | β | β | float | Minimum height | |
| maxWidth | β | β | β | float | Maximum width | |
| maxHeight | β | β | β | float | Maximum height | |
| widthWeight | β | β | β | float | Width ratio to parent | UIKit only |
| heightWeight | β | β | β | float | Height ratio to parent | UIKit only |
| aspectWidth | β | β | β | float | Width aspect ratio | |
| aspectHeight | β | β | β | float | Height aspect ratio | |
| maxWidthWeight | β | β | β | float | Maximum width ratio to parent | UIKit only |
| maxHeightWeight | β | β | β | float | Maximum height ratio to parent | UIKit only |
| minWidthWeight | β | β | β | float | Minimum width ratio to parent | UIKit only |
| minHeightWeight | β | β | β | float | Minimum height ratio to parent | UIKit only |
| weight | β | β | β | float | Layout weight for orientation layouts | |
| compressHorizontal | β | β | β | string | Horizontal compression resistance: Required, High, Low, Fit | UIKit only |
| compressVertical | β | β | β | string | Vertical compression resistance: Required, High, Low, Fit | UIKit only |
| hugHorizontal | β | β | β | string | Horizontal content hugging: Required, High, Low, Fit | UIKit only |
| hugVertical | β | β | β | string | Vertical content hugging: Required, High, Low, Fit | UIKit only |
Android XML Attribute Mappings
When using KotlinJsonUI's XML generation, common attributes are mapped as follows:
Layout Attributes
widthβandroid:layout_width(matchParentβmatch_parent, wrapContentβwrap_content)heightβandroid:layout_height(matchParentβmatch_parent, wrapContentβwrap_content)padding/paddingsβandroid:padding(individual padding values)marginsβandroid:layout_margin(individual margin values)visibilityβandroid:visibility(visible, invisible, gone)alphaβandroid:alpha(0.0-1.0)
Style Attributes
backgroundβandroid:background(colors or drawable resources)cornerRadiusβ Generated drawable with rounded cornersborderWidth/borderColorβ Generated drawable with bordershadowβandroid:elevation(for Material Design shadows)
Alignment Attributes
centerInParentβandroid:layout_centerInParent(RelativeLayout)alignTop/alignBottomβandroid:layout_alignParentTop/Bottom(RelativeLayout)weightβandroid:layout_weight(LinearLayout)
For complete XML mapping details, see KotlinJsonUI XML Support