How to create a custom code button that plays audio

I am looking for a code example of a custom label that functions as a button but does not used main.storyboard its all code. Once you press the custom label I would like the button to play a audio clip. Thanks.

At first, why you don’t use normal button to play video…?

You can create custom button - as you want label which treat as a button…two ways :

  1. Create a lable with all your requirements and then add tap gesture to it. It will treat as a button. on tap gesture play your video.
  2. Create a view, create image view if you want and add to view, create label if you need and add it to view then finally create a blank button (button type-custom, text color-nil, font size-1, tint color-nil, background color-nil, background image-nil, image-nil) and then add button to view. On tap of button you can play video.

These things you can do by programmatically or by storyboard(.xib)