This is often difficult to do, as many owners feel badly that their dog is asking for attention; however remember that in the long run a brief few minutes of not giving attention will pave the way for a lifetime of a dog that does not bite you…this is a great trade off.
Do not look at your dog, do not speak, do not touch your dog. Your Yorkie has already been given the 1st message of your “Ouch!” that his actions caused you pain. Now, you must train your dog that biting = being ignored, having zero fun and life is boring and that not biting = fun, attention, play time, treats and praise.
It is best if you can accomplish this without placing your Yorkie in his gated area/playpen. Because you'll want him to realize that it is his behavior that is causing him to be ignored, not his positioning in a confined area. However, if he is literally nipping at your heels and making it difficult to socially isolate him by ignoring him, you will then want to opt to place him in his area for a 'time out'.