Uruguay's settlement was a contested affair, as was the whole region around rio de la plata and paraná river. Officially Portugal shouldn't have the right to settle that far west, by the treaty of Tordesillas (1494) that divided the Americas and the world between the two Iberian countries. But finding out your longitude at those times was very difficult, so the Portuguese contested that they actually had a right to settle some places. Also, more importantly, Portugal and Spain became united in the Iberian Union (1580-1640), which ended officially only with a peace deal in the 1660s. During the time of the Iberian Union, colonists from both countries settled wherever they chose, as they answered to the same king. The Portuguese settlers then started going westwards, and that is how Brazil got much bigger than it had any right to be.
In 1680, Portugal started settling the eastern bank of rio de la plata. The Portuguese king of the time thought they had the right to settle there according to the Tordesillas treaty. On a more cold, geopolitical analysis, the Portuguese interest in the region was to try to control the rio de la plata, which was the fastest way to reach the interior of South America before the invention and constructon of railroads. So was Colonia del Sacramento founded, and the city to this day has a different pattern than the Spanish-founded cities, reflecting its Portuguese origins.
Lots of conflicts happened between the Portuguese and the Spanish over who had the right to settle Uruguay and the surrounding regions. The Portuguese used different kind of strategies to occupy those regions, compared to what they did in the Brazilian Northeast or in Sao Paulo. To this day the Brazilian South has some differences in society that reflect these differences in settlement. Instead of big plantations with lots of slaves, the Brazilian South was settled with soldiers and people that were landless in Portugal, and especially the Azores, creating a society that was not as dependent on slavery and could raise a militia quickly to defend the settlements or to invade another land. This way Portugal, and later Brazil, got to settle the states of Rio Grande do Sul and Santa Catarina.
The Portuguese plan was to do the same thing with Uruguay, but the Spanish were able to defend that place better, due to the proximity of the city of Buenos Aires. Officially the SPpnish recognized the Portuguese right to Colonia del Sacramento in 1681, but the place (and the rest of Uruguay) changed hands a lot in the wars of the 18th century. In the Treaty of San Ildefonso (1777) Uruguay became a part of Spain again, and this time was settled with many Spanish-speaking people. The Portuguese/Brazilians would invade the place again in 1816, after the Napoleonic Wars, during the independence wars of the Spanish colonies, as part of their long geopolical strategic plans and, officially, because the place was a mess with a civil war between Spanish loyalists and two types of independence fighters in the old La Plata Viceroyalty (federalists x those who wanted a government centered around Buenos Aires). That was the time when the place received the name "Provincia Cisplatina". The Portuguese/Brazilians ruled the place from 1816 to 1828, but most of the population was Spanish speaking coming from the time of the Treaty of San Ildefonso.
After Brazil seceded from Portugal, in 1822, the Uruguayans started to rebel to get their own independence, helped by the Argentineans who lived on the other side of the river. In 1825, a 3 year war ensued, in which the Brazilians lost the land battles but won the naval battles, blockading Buenos Aires, for example. This war was very unpopular in Brazil, and was one of the reasons the first Brazilian emperor, D. Pedro I, was forced to abdicate and go back to Portugal. The British mediated a peace treaty, by which Uruguay became indpendent from Brazil, but wasn't annexed by Argentina (who wanted to recreate the La Plata Viceroyalty at the time). Every naton would get free navigation rights in the la plata river, as no nation would control the shores on both side of the river (at least in the bay near the ocean).