Implementing round buttons - ios

I am building a simple app that displays a grid, similar to a guitar neck, and I wanted to draw oval buttons at each intersection of the grid, and attach behaviors to it, like tapping once for sound. Pretty straight forward stuff...
My question is about the use of class for the buttons.
I am able to draw some good looking buttons with UIBezierPath/bezierPathWithOvalInRect:
and now I want interactivity. I read in this forum from one developer that he used a button underneath an image to capture user interaction. I have tried that but I cannot fade out the button all together, as interaction is removed altogether.
Is it possible to draw rounded buttons with UIButton from interface builder?
What is best practice for something simple like drawing rounded buttons and capturing user interaction?

you can try layer.cornerRadius using the QuartzCore framework.
Or, just use an image as a custom button.

Related

Best way to create Custom (Octagonal) UIButton in Swift

I am about to customize all of my UIButtons by subclassing them into a special UIButton class and I want to have the "look and feel" like below octagonal or some hexagonal buttons. What would be the best way to create such shape UI buttons? So far, I only know how to create rectangle, circular and rounded-edge buttons, and I could not find SO answers or cocoapods for below "look and feel".
Is it possible to create a custom class of such UIButton programmatically?
Or do I need to import an image onto a button to realize below "look and feel"?
Also, could there be any possibility be that App Store does not allow such custom shape buttons?
Yes you can use UIBezierPath to create arbitrary shapes for a variety of UIKit components that includes UIButton. See tutorial here
I think the above is achievable simply using #1 above in combination with myButton.layer.borderColor/.borderWidth
I am not sure. My guess would be no but I think it would depend on the Apple Human Interface guidelines which seem to be arbitrary in some cases. For what it's worth, I've shipped apps that had very similar buttons but they were elipses and not polygons like you have but still appear very similar.
Update: Forgot about a great example. This is an example of a "bookmark tab" effect I created using a UIButton with a UIBezier path. This has been shipping for years at this point with no issues:

Make clickable segments of irregular shape in iOS app

I want to make custom system to control some parameters of each room from iPad. I'd like to make each segments, which is shown on screenshoot, clickable, and the problem is that i don't understand how to make them clickable as buttons. Can somebody help with this task? I'm using Swift 4 and iPad Pro 9,7.
Building plan with coloured segments
The native UIButton does not allow this.
Your best bet would be to describe the plan as a set of CGPaths and hit test them.
You can have an UIView representing the floor plan, each room is a CGPath owned by the view and a custom UITapGestureRecognizer on the view that tests each of the CGPaths.

Create Custom shaped button using CALayer

what is the best way to achieve the following.
Basically what I want to do is to create an "intractable area" where the user can touch and subsequent actions will take place. For example in the picture the user taps the green area a pop is presented with some options. Similarly there would be different colour "intractable areas or buttons" with in that pizza slice, if you may.
I was thinking of having buttons created through CALayer and try to fit them with in the bounds of the empty state image, but i don't know how to achieve this. Any other ideas are well appreciated.
I would subclass UIButton or UIControl to make your custom button. Then override pointInside:withEvent: to see if the touch event is within the correct region.
See these links for more info and ideas:
Non-Rectangular Buttons on iOS
Abusing UIView (see section on pointInside:withEvent:)
How to create a transparent window with non-rectangular buttons?
iPhone button with non-rectangle shape?
OBShapedButton

How to create a see through button with "blurred" background in iOS 7

I am updating my app to iOS 7 and wanted to improve the UI. I want to create a see through background like Control Center. So basically I have a button, which I would like to have a see through and "blurred" background like control center. Thanks!
There's nothing to stop you using a UIToolbar.
Create a UIView as a base view with clear background, add a UIToolbar anchored to it's edges so it fills the view and then add your other controls to your base view above the toolbar.
It'll look for example like this:
The blurring effect is not available as a public API. There are third party implementations available, such as FXBlurView, which I can recommend.
You shouldn't really be using a toolbar. It's called toolbar for a reason.
One way to go would be to take a snapshot image of your background and blur it (you can use UIImage+ImageEffects category included in Apple samples to achieve consistent effect).
You can then just crop the image to desired frame and use it as a background of your button.
Are you looking to have a 'dynamic' blur effect (like in Control Center)? It's still doable, but it makes things more complicated.
You can also create blur effects with GUPImage Framework here is a full tutorial about it iOS blur effect tutorial. The tutorial also explains why you shouldn't use toolbar for blur effect creation

Designing a circular "selector" control

I'm developing an app that calculates poker odds, and now I'm facing some problems with the card selector.
This is a mockup of what I want.
I've found two ways to accomplish this. The first one is to use an entire UIImageView and detect touches, calculate where the touch has been generated, and set the corresponding value.
The second one is to use a lot of UIButtons, but in this case I get problems with the shape of the buttons.
Of course I can use a regular UIPickerView and so on but I think that the one I've designed is better.
if you have a UIButton with a background image that is shaped irregular. then that is the only point that the button can be pressed.
Change the type to custom and put your slices into buttons.
This has been my experience anyhow.
My buttons have to have a .01 alpha background to increase their pad size and people can push the button.
Hope that helps :)
After googled a little i've found https://github.com/ole/OBShapedButton .
it does anything what i need

Resources