iOS Button#

#

Added in version 2.0.1.

A behavior that implements an iOS-style interactive button.

The IOSButtonBehavior class provides a touch-responsive button behavior inspired by the interaction of buttons in iOS. When the user presses the widget, it smoothly scales up and activates the corresponding glass/touch response. When the touch is released, the widget smoothly returns to its original scale.

The behavior can be combined with other widgets or behaviors to create custom interactive components.

Example#

from kivy.lang import Builder

from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.behaviors import IOSGlassBehavior, IOSButtonBehavior
from kivymd.app import MDApp

KV = '''
MDScreen:

    FitImage:
        id: bg_image
        source: "https://picsum.photos/800/600?random=2"

    GlassContainer:
        target_background: bg_image
        border_radius: [dp(26), dp(26), dp(26), dp(26)]
        glass_color: [1.0, 1.0, 1.0, 0.18]
        blur_amount: 10.0
        size_hint: None, None
        size: "400dp", "200dp"
        pos_hint: {"center_x": .5, "center_y": .5}
'''


class GlassContainer(IOSGlassBehavior, IOSButtonBehavior, MDBoxLayout):
    pass


class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)


Example().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ios-button-behavior-example.gif

Note

Use the ButtonBehavior class only in conjunction with the IOSGlassBehavior class.

class GlassContainer(IOSGlassBehavior, IOSButtonBehavior, MDBoxLayout):
    ...
class GlassContainer(IOSButtonBehavior, MDBoxLayout):
    ...

API - kivymd.uix.behaviors.ios.button_behavior#

class kivymd.uix.behaviors.ios.button_behavior.IOSButtonBehavior(**kwargs)#

Implements iOS-style interactive button behaviors.

Provides touch-responsive feedback by applying smooth scaling animations and tracking touch positions for glass glare effects. On press, the widget scales up to 110% and updates press intensity factors. On release, it returns to its original scale with a spring-back transition.

For more information, see in the ButtonBehavior class documentation.

press_scale_transition#

The type of transition for the scale-up animation on touch down.

GlassContainer(
    press_scale_transition="out_elastic",
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ios-button-behavior-press-scale-transition.gif

press_scale_transition is a StringProperty and defaults to ‘easing_accelerated’.

press_scale_duration#

The duration of the scale-up animation on touch down in seconds.

GlassContainer(
    press_scale_duration=2,
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ios-button-behavior-press-scale-duration.gif

press_scale_duration is a NumericProperty and defaults to 0.14.

release_scale_transition#

The type of transition for returning to original scale on touch up.

GlassContainer(
    release_scale_transition="out_elastic",
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ios-button-behavior-release-scale-transition.gif

release_scale_transition is a StringProperty and defaults to ‘out_back’.

release_scale_duration#

The duration of returning to original scale animation on touch up in seconds.

GlassContainer(
    release_scale_duration=2,
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ios-button-behavior-release-scale-duration.gif

release_scale_duration is a NumericProperty and defaults to 0.22.

on_touch_down(touch)#
on_touch_move(touch)#
on_touch_up(touch)#