# How to create a custom code button that plays audio

**URL:** <https://forums.kodeco.com/t/how-to-create-a-custom-code-button-that-plays-audio/18721>\
**Category:** Swift\
**Created:** [August 21, 2016, 4:50am UTC](https://forums.kodeco.com/t/how-to-create-a-custom-code-button-that-plays-audio/18721 "2016-08-21T04:50:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zalubski](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zalubski/32/81494_2.png) [@zalubski](https://forums.kodeco.com/u/zalubski)\
**Post date:** [August 21, 2016, 4:50am UTC](https://forums.kodeco.com/t/how-to-create-a-custom-code-button-that-plays-audio/18721/1 "2016-08-21T04:50:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vimipatel](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vimipatel/32/83106_2.png) [@vimipatel](https://forums.kodeco.com/u/vimipatel)\
**Post date:** [August 27, 2016, 5:57am UTC](https://forums.kodeco.com/t/how-to-create-a-custom-code-button-that-plays-audio/18721/2 "2016-08-27T05:57:18Z")

</div>

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)
