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()
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.behaviors import IOSGlassBehavior, IOSButtonBehavior
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.fitimage import FitImage
from kivymd.uix.screen import MDScreen
class MyScreen(MDScreen):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
bg_image = FitImage(source="https://picsum.photos/800/600?random=2")
self.widgets = [
bg_image,
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 MyScreen()
Example().run()
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
ButtonBehaviorclass documentation.- press_scale_transition#
The type of transition for the scale-up animation on touch down.
GlassContainer( press_scale_transition="out_elastic", )
press_scale_transitionis aStringPropertyand defaults to ‘easing_accelerated’.
- press_scale_duration#
The duration of the scale-up animation on touch down in seconds.
GlassContainer( press_scale_duration=2, )
press_scale_durationis aNumericPropertyand 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", )
release_scale_transitionis aStringPropertyand 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, )
release_scale_durationis aNumericPropertyand defaults to 0.22.
- on_touch_down(touch)#
- on_touch_move(touch)#
- on_touch_up(touch)#