You are here: Creating a Button Using a Constructor: kony.ui.Button

Button Widget

Button widget is a UI element that is used to trigger any actions. These actions can be navigating to another form, perform animations, interacting with a dialog box, etc.

A button displays text with a background image or a background color.

Button widget is employed in many scenarios where the user performs an on-click action on a button. Some of them are:

Widgets are normally added to your Kony application using Kony Visualizer, but can also be added from code. For general information on using widgets in Visualizer, see Designing an Application in the Kony Visualizer User Guide.

For general information on the Button widget see the Button topic in the Kony Visualizer User Guide.

The Button widget capabilities can be broadly categorized into the following:

Layout

Events Description
doLayout

Invoked for every widget when the widget position and dimensions are computed.

 
PropertiesDescription
anchorPoint Specifies the anchor point of the widget bounds rectangle using the widget's coordinate space.
bottomDetermines the bottom edge of the widget and is measured from the bottom bounds of the parent container.
contentAlignment Specifies the alignment of the text for a widget with respect to its boundaries.
centerXDetermines the center of a widget measured from the left bounds of the parent container.
centerYDetermines the center of a widget measured from the top bounds of the parent container.
heightDetermines the height of the widget and measured along the y-axis.
left Determines the lower left corner edge of the widget and is measured from the left bounds of the parent container.
maxHeightSpecifies the maximum height of the widget and is applicable only when the height property is not specified.
maxWidthSpecifies the maximum width of the widget and is applicable only when the width property is not specified.
minHeightSpecifies the minimum height of the widget and is applicable only when the height property is not specified.
minWidthSpecifies the minimum width of the widget and is applicable only when the width property is not specified.
padding Defines the space between the content of the widget and the widget boundaries.
paddingInPixelIndicates if the padding is to be applied in pixels or in percentage.
right Determines the lower right corner of the widget and is measured from the right bounds of the parent container.
topDetermines the top edge of the widget and measured from the top bounds of the parent container.
widthDetermines the width of the widget and is measured along the x-axis.
zIndex

Specifies the stack order of a widget.

UI Appearance

PropertiesProperties
backgroundColorSpecifies the background color of the widget in hex format.
blockedUISkin Specifies the skin that must be used to block the interface until the action in progress (for example, a service call) is completed.
clipView Defines a shape to clip the widget view.
focusSkin Specifies the look and feel of the Button when in focus.
glowEffect Specifies if there must be glow effect when you touch the button.
hoverSkin Specifies the look and feel of a widget when the cursor hovers on the widget.
pressedSkin Specifies the skin to indicate that the Button is pressed or clicked.
rippleBackground Defines the ripple background for a Button Widget.
shadowDepth Defines the depth of the shadow effect applied to the Button Widget.
shadowTypeSets a type of the shadow effect to apply to the Button Widget.
showProgressIndicator Specifies if the progress indicator must be displayed when the button is clicked.

  Animations

MethodsDescription
animate Applies an animation to the widget.
 
PropertiesDescription
transform Contains an animation transformation that can be used to animate the widget.
widgetSwipeMoveUsed to enable and configure the left or right swipe actions for a widget.
  

Data Management

MethodsDescription
cloneWhen this method is used on a container widget, then all the widgets inside the container are cloned.

  

PropertiesDescription
cacheConfigUsed to configure the cachePolicy and storagePolicy of the cache responses.

3D Touch

MethodsDescription
registerForPeekandPop Registers a widget to enable 3D Touch peek and pop gestures.
setOnPeek Sets and overrides the existing onPeekCallback for the widget.
setOnPop Sets and overrides the existing onPopCallback for the widget.
unregisterForPeekandPop Unregisters a widget from 3D Touch peek and pop gestures.
 

User Input Handling

EventsDescription
onClickAn event callback is invoked by the platform when the user performs a click action on the button.
onScrollWidgetPosition An event callback is invoked by the platform when the widget location position gets changed on scrolling.
onTouchEnd An event callback is invoked by the platform when the user touch is released from the touch surface.
onTouchMove An event callback is invoked by the platform when the touch moves on the touch surface continuously until movement ends.
onTouchStart An event callback is invoked by the platform when the user touches the touch surface.
 
MethodsDescription
addGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
removeGestureRecognizerAllows you to remove the specified gesture recognizer for the specified widget.
setGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
 

Enabling RTL

PropertiesDescription
retainContentAlignmentHelps to retain the content alignment of the widget while applying RTL.
retainFlexPositionPropertiesHelps to retain the left, right and padding properties while applying RTL.
retainFlowHorizontalAlignmentEnables you to change the horizontal flow of the widget from left to right.

Miscellaneous

MethodsDescription
getBadge Enables you to read the badge value (if any) attached to the specified widget.
setBadge Enables you to set the badge value to the given widget at the upper, right corner of the widget.
setCursor Applies to all widgets for the Windows Desktop channel. Customizes the cursor when hovered on widgets.
 
PropertiesDescription
buttonTypeSupports native iOS button types.
contextMenu Used add a menu that appears upon clicking a button.
cursor Enables you to control the cursor property for the Windows Desktop channel.
cursorTypeSpecifies the type of mouse pointer used.
customCursor Enables you to configure a custom cursor for Windows Desktop channel.
enableHapticFeedback Allows you to enable or disable haptic feedback on the Button widget.
externalURL Specifies that the URL must be opened directly from the web site without having to contact the Kony Server.
nativeButtonFocusImage Allows you to set an image to be used when the button has focus.
nativeButtonNormalImageAllows you to set an image to be used for a button.
rawBytes Specifies the rawbytes representing an image that can be used as a background for the button.
text Specifies a general or descriptive text for the Button widget.
toolTip

Specifies the hint text when the cursor hovers over a widget, without clicking it.

  

Configurations common to all widgets

MethodsDescription
blurEnables you to make the widget look unfocused.
convertPointFromWidgetAllows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
convertPointToWidgetAllows you to convert the co-ordinate system from point(receiver's co-ordinate system) to a Widget.
removeFromParentAllows you to remove a child widget from a parent widget.
setEnabled Specifies the widget that must be enabled or disabled. Syntax
setFocus Specifies the widget on which there must be focus.

setVisibility

Use this method to set the visibility of the widget.
 
PropertiesDescription
enableCache Enables you to improve the performance of Positional Dimension Animations.
info A custom JSObject with the key value pairs that a developer can use to store the context with the widget.
isVisible Controls the visibility of a widget on the form.
parent Helps you access the parent of the widget.
 
EventsDescription
postOnclickJSAllows the developer to execute custom JavaScript function after the onClick callback of the widget is invoked.
preOnclickJS Allows the developer to execute custom JavaScript function before the onClick callback of the widget is invoked.

Button Widget Basics

Creating a Button Using a Constructor: kony.ui.Button


var button1 = new kony.ui.Button(basicConf, layoutConf, pspConf);

Note: The configuration properties should be passed only in the respective configuration objects otherwise they are ignored

Example

//The below function is the callback function for onClick event call.
function onClickCallBack() {
    //Write your logic here.
}

//Defining the button with onClick:onClickCallBck.
var btnBasic = {
    id: "Onbutton",
    isVisible: true,
    skin: "btnSkin",
    focusSkin: "btnFSkin",
    text: "Click Here",
    onClick: onClickCallBck
};

var btnLayout = {
    containerWeight: 100,
    padding: [5, 5, 5, 5],
    margin: [5, 5, 5, 5],
    hExpand: true,
    vExpand: false,
    displayText: true
};

var btnPSP = {
    pressedSkin: "presSkin",
    externalURL: "https://www.kony.com", 
   submitURL: "https://www.kony.com",
    glowEffect:true
}; //Creating the button. var Onbutton = new kony.ui.Button(btnBasic, btnLayout, btnPSP);

Customizing a Button's Appearance

You can customize the appearance of the button using the following properties:

Important Considerations

The Button Widget has the following considerations:

Set a background image for a Button

premCopyright © 2012 Kony, Inc. All rights reserved.
premCopyright © 2012 Kony, Inc. All rights reserved.