Difference between Buttons and onTapGesture - swift

I’m quite new to swiftui and I was curious on what’s the difference between using a button displaying an image or an image with onTapGesture modifier that make an action just like the action on buttons.

In the use case you've described you can use either but for reference, Apple provides the following guidance in their documentation for onTapGesture:
If you are creating a control that’s functionally equivalent to a Button, use ButtonStyle to create a customized button instead.
onTapGesture adds an action to perform when the view recognizes a tap gesture and can be tailored to respond to any number of taps (with 1 being the default).
Buttons are a control that performs an action when triggered and have the benefit of automatically adapting their visual style to match the expected style within different containers and contexts.
In iOS and watchOS, the user triggers a standard button by tapping on it.
In macOS, the user triggers a standard button by clicking on it.
In tvOS, the user triggers a standard button by pressing “select” on an external remote, like the Siri Remote, while focusing on the button.
For more information please refer to Apples documentation here: https://developer.apple.com/documentation/swiftui/text/ontapgesture(count:perform:)
https://developer.apple.com/documentation/swiftui/button

I would recommend using Button when you want the feature of a button. I noticed that images cannot be used as buttons with Voice Over on. When I changed those to use Button instead, it fixes the problem.

Related

Is there a way to add ui elements from code in netlogo?

In netlogo, the way to add say, a button is to click on the add button and select button demonstrated here. is there a way to do this from code, say when the setup button is clicked? I want to generate some monitors demonstrating some information after the setup button is clicked.
The eXtraWidgets extension allows you to create additional interface tabs in the NetLogo GUI and programatically put custom widgets on them.
Unfortunately, it doesn't work (yet) with NetLogo 6.0.
There also used to be the Goo extension, but it has been unmaintained for a while.

NSButton in Swift, handle click and release events

i'm trying to manage different state of a simple push button on an OS X application : When the user click on it, and when the user release the click.
Currently i set my button type by NSMomentaryLightButton
NSMomentaryLightButton When the button is clicked (on state), it
appears illuminated. If the button has borders, it may also appear
recessed. When the button is released, it returns to its normal (off)
state.
This type of button is best for simply triggering actions because it
doesn’t show its state; it always displays its normal image or title.
This option is called Momentary Light in Interface Builder’s Button
inspector
I thought it was the good way, but when i print my button status, it's like a toggle button than the push button that i set. As you can see on exemple gif
To sum up, How can i have a real push button behaviour ? Call function when the user click on it, and when the user release the click.
Thank,
You don't want to use buttons for piano keys. First, they are non-rectangular, and they don't act as buttons do: neither single-action push-button, nor toggle switches. You are interacting in a custom way, with a custom view, meaning the NSButton control hierarchy isn't called for. Instead you're subclassing NSView and capturing low-level mouse events as detailed here:
https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1
You found this yourself as you detailed in your own comments, but I wanted to make sure you had a higher level point of view. It's even possible, and probably best, to consolidate all of the piano keys into a single view, and let the keys themselves be rendered using NSBezierPath and perform mouse hit detection using containsPoint:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/#//apple_ref/occ/instm/NSBezierPath/containsPoint:
This is a lot more work but the only way to make a truly professional looking piano simulation. Then you can render the keys with whatever outline, fill, and labeling you need without the limitations of built-in button shapes and layout. You could even have the bottom edges of the keys slightly rounded, for example, or apply a shiny texture.

iOS Keyboard and Custom Buttons

How can I embed custom keyboard buttons inside the iOS Default keyboard, like the "UP" app by Jawbone has done in the picture below.
I am looking to embed an "#" button identically to how the app has done it (I don't need the # button). I have found ways to add buttons above the keyboard or change the keyboard style (the email style includes the # button but adds unneccessary ones and makes the space button to small) but no way to seamlessly integrate it like above.
That is not a custom button, that is the keyboardType UIKeyboardTypeTwitter.

Is it possible to remap the headset buttons

Is it possible using the SDK to change the bluetooth headset/remote buttons behavior. I would like to capture the button press(es) and perform some action, eg, skip next track, launch popup etc
I think you will receive appropriate callbacks from iOS when a button is pressed, and within these callbacks you can decide what to do.

how to do tooltip on button in iphone?

I am having download icon on my page i want that when the user takes his finger over the button a tooltip should show as showing download in text.
is there any option in iphone to show a tooltip???
Dan is absolutely right on how to do it but I'd answer you should rethink your design to not need the tooltip at all.
There's a reason that there isn't one by default - what if the user presses down on the button to see what it does, reads the tooltip and realises that's not what they want. They then have to be very careful not to let go while still over the button or it will press and do the wrong thing. (And most users don't know that they can press down over a button, move their finger off it and release it to cancel the press.)
You should rethink your design to make it obvious what the buttons do without the user having to interact with them first.
However, if you definitely still want a tooltip, Dan's method is fine.
Nothing built-in, no. If you think about it, generally a tooltip appears when you mouse over the target item. There's no "mousing over" with a touch interface.
You can definitely roll your own, though. Start by placing a view containing your tooltip contents exactly where you want it with an alpha of 0%. Make a custom button with no content that outlines your download icon, and hook its "touch down inside" action to a method that animates the tooltip view to an alpha of 100%. Hook your button's "touch up inside" , "touch down outside" and "touch up outside" actions (and maybe some others--you might want to experiment with that) to a method that animates the tooltip view back to an alpha of 0%.
There isn't native support for this in iOS. But you can create your own.
I ended up creating my custom tooltip/popover class.
Can be initalised with any content view and dynamically adjusts it's frame.
Hope it helps.
https://github.com/akeara/AKETooltip