When by itself or accented, the Spanish letter I is pronounced "ee," as in see or fee, but without the "y" sound at the end.
|i||the letter i|
When I is unaccented and preceded or followed by a strong vowel, it diphthongs with that vowel and is thus pronounced more like "y":
Type of vowel
|Hard vs soft||I is a soft vowel|
|Strong vs weak||I is a weak vowel|
Please note that this explanation is only a guideline for the Spanish that I know, which is Castilian Spanish. There are many regional variations in Spanish pronunciation.