Former Barcelona midfielder Andrés Iniesta has announced his retirement from football at the age of 40.