2

First off, I know that questions similar to this have been asked and answered many times, however, none of them are quite what I'm looking for.

I'm trying to create a button that is a circle/oval. The button should respond normally to touches inside the oval and not respond when there is a touch outside. the problem I'm having is that no method Ii have tried prevents the button from responding when the corner of the rectangle (outside the oval) is touched.

Essentially, the button needs to not only look like an oval, but respond as one also.

Any help would be greatly appreciated!

Edit: So i figure im going to need to build a custom control. this is for a side project so it may take a bit, but ill make it available on github and post a link to it here. thank you for the input!

2
  • 1
    There is nothing like this that comes out of the box. Unless you are willing to use physics bodies from SceneKit. If you want a solution in UIView consider writing your own. It should be fairly simple. Commented Jul 19, 2015 at 21:48
  • possible duplicate of how to detect touches inside a circular view Commented Jul 20, 2015 at 0:42

2 Answers 2

1

Not entirely sure if this is what you're wanting, but if you click on your UIButton, go to the Identity Inspector tab on the right, go to where it says User Defined Runtime Paths and click the + button and enter this info:

Key Path: layer.cornerRadius 
Type: Number
Value: Any number

For a completely rounded circle, make the value 1/2 the value of the height of the button. You can play around with different values to get your desired look.

NOTE: The rounded corners won't show on storyboard. But they do show on the simulator.

Couldn't really tell if this is what you were wanting based on your question. Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

yea cornerRadius, adding layers, and similar change the appearance only of the button.. not the area that responds to touches...
0

You could always create a button and set the background of the button to be an oval.

1 Comment

if you do not understand feel free to ask for clarification

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.