Since your button action, added programmatically as a #selector for your button, takes the button itself as a parameter. (sender:UIButton?), you can tell which button was pressed even if you use the same action for all buttons. One easy way to do this is to look at the button's title. If you make the button title the file name, then by looking at the title, you know the filename of the PDF you should show. Another way (and this is my preferred way) is to use the tag. The tag field of a button is an integer that the programmer can use for any purpose they want. So you give one button a tag of 1, another a tag of 2, or whatever, and stores the filenames in an array. Use the tag to get you the index of the filename array...and then you can use whatever you want as the title of the button. Use "math" to work out how large the ScrollView should be. Base the size of the ScrollView On the number of PDF files in your folder. Don't make the ScrollView too large or too small.