Essentially Spain was destroyed by the Peninsular War and was in a state of constant warfare from 1808 (1804 if we count the wars against England) to 1826, fighting a fourteen year-long colonial war in the Americas. After that Spain was left without ships, cash or army and right after the Carlist War erupted and ruined any modernisation attempt. After that Spain just kept fighting against itself, except for a brief period in which general O'Donnell tried to center the attention of the country with foreign wars (Spain invaded Vietnam, Morocco, the Dominican Republic and Mexico while also being at war with Ecuador, Peru, Bolivia and Chile). If somehow his unstable expansive government survived longer maybe we could have Spain control a large chunk of Africa, probably Cameroon, Gabon and some other extra colonies. Then the 1868 revolution happened and the Cuban Wars began. Spain had too many troubles trying to control Cuba and the Philippines to really care for Africa. After all, these two colonies were mostly developed and more valuable than any land the Spanish could get in Africa at the point. After the Spanish-American War there was a surge in African colonialism, but it was too late already. If we want a Spanish African empire we'd have to either keep a militaristic and aggressive Spain or for it to lose Cuba before the Berlin Conference.