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

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 corners
  • borderWidth/borderColor β†’ Generated drawable with border
  • shadow β†’ 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