We've been keeping pigs for about 6 years, and we've found that nothing will keep a pig from getting out of any kind of enclosure if it really wants to. The trick is, therefore, to encourage it to stay home...
We try and feed at the same times every day. That way, the pigs know when the next lot of food will be due, and will wait in rather than go foraging. Because they're outside, with plenty of dirt to get their snouts into, they don't get bored; too small an enclosure is a bad idea.
The only fencing which discourages them is electric. They get the hang of it very quickly. We used to have 2 brood sows, one very dominant; she used to test the electric wire once a day by shoving her sister into it and seeing if she squealed. As soon as the fence battery went low, she was through the wire and off exploring.
We spent a lot of money on posts and conventional wire netting and barbed wire before we tried electric; all wasted. The brood sows used to love scratching their necks and ears on the barbed wire in summer, when the heat made them itchy.
I always feed the pigs from the same bucket, which is bright yellow. When they get out, all I have to do to get them back in is load food into the yellow bucket, and they trot along after me like spaniels as I lead them back into the pen. Early on, I made the mistake of trying to chase them back in with loud cries, threats and foul language. This just spooked them and made them determined not to do anything I wanted them to.
Hope this helps
Tom