iOS Native#

#

Added in version 2.0.1.

Behavior that provides a bridge for native iOS APIs using pyobjus, supporting haptic feedback and other platform-specific capabilities for KivyMD components.

Example#

from kivy.metrics import dp

from kivymd.app import MDApp
from kivymd.uix.behaviors import IOSNativeBehavior
from kivymd.uix.button import IOSButtonText, IOSButton
from kivymd.uix.fitimage import FitImage
from kivymd.uix.screen import MDScreen


class VibrateIOSButton(IOSButton, IOSNativeBehavior):
    def on_press(self):
        super().on_press()
        self.trigger_haptic_feedback()


class Example(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        bg_image = FitImage(source="https://picsum.photos/800/600?random=2")

        return MDScreen(
            bg_image,
            VibrateIOSButton(
                IOSButtonText(
                    text="Tap for Haptic",
                ),
                target_background=bg_image,
                pos_hint={"center_x": 0.5, "center_y": 0.5},
                border_radius=[dp(22)] * 4,
                adaptive_width=True,
            ),
        )


if __name__ == "__main__":
    Example().run()

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

class kivymd.uix.behaviors.ios.native_behavior.IOSNativeBehavior(**kwargs)#

Behavior that provides a bridge for native iOS APIs using pyobjus, supporting haptic feedback and other platform-specific capabilities for KivyMD components.

trigger_haptic_feedback() → None#

Triggers the native iOS selection haptic feedback.

check_and_trigger_haptic(value: float) → None#

Calculates discrete steps using widget’s min/step attributes and triggers haptic feedback if the step has changed.