0

I am looking for simple way how to create a button (or other subclass of UIView) that is not drawn in all its frame but only within specified inner (inset) rectangle. The inner (inset) rectangle will have rounded corners of some custom radius. Picture below demonstrates it:

enter image description here

To summarise:

  • control will respond to touch events within all its frame (the outer rectangle)
  • content, background, etc. of the control will only by drawn in the inner (inset) rectangle
  • size of inner rectangle and its corner radius must be customisable

Subclassing is an option but it there is simpler solution I will go with that.

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • This doesn't answer your question, but it provides a way to accomplish what you want to do. http://stackoverflow.com/questions/808503/uibutton-making-the-hit-area-larger-than-the-default-hit-area – Tim Quinn Oct 23 '14 at 06:43

1 Answers1

1

This can be achieved by one of the following ways :

  • Add a subView inside custom button and provide its corner radius some value so that it becomes rounded. You can add the background , content etc. to this view. But this has to be a custom button and you need to handle the addition of contents by providing some API's.

  • Another option will be to add a layer with rounded corner inside button but with this limitation comes. You cannot add a subview to your inset rectangle(sublayer). You can only add layers to it not a view.

Amit
  • 1,043
  • 1
  • 10
  • 32