Why is melanin black?
Let's do a quick mind experiment. Imagine a ray of UV light hitting a white molecule in the skin. White generally reflects light, so that UV light would bounce off, and potentially could hit something much more critical. Black, on the other hand, absorbs light, so the energy in the UV light would be absorbed by melanin rather than other, more sensitive molecules. According to this article:


  eumelanins are capable of dissipating >99.9% of absorbed UV and
  visible radiation through nonradiative means.


Eumelanins are the most commmon type of melanin. Incidentally, not all melanin is black.

Another quick note, somewhat relevant: Try not to think of evolution as having a goal or purpose. Melanin being black is a result of random changes that happened to result in a beneficial phenotype. It didn't conclude that something was needed to counteract UV light and try to reach that goal.