Make clickable segments of irregular shape in iOS app - ios

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.

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:

How to implement action buttons around circular group in Apple Watch

I would like to implement an interface where the buttons need to be placed around a circular group object. All buttons need to be arranged around the circle in the circular order. It is similar to contacts interface provided by Apple Watch while side button is pressed. I keep thinking how apple would have implemented that. Watchkit framework doesn't allow the developer to set X&Y of the UI elements to position whereever we want. It would be great if someone can help me on how to do this technically.
PS:I need buttons around the circle as they have to be actionable.

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

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

Implementing round buttons

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.

Resources