Elements are ionized because they aspire to be stable. The most stable form are the ones with full octet of electrons, the noble gases which consist of the last column in the periodic table. The rest of the elements either accept or readily donate electrons to conform to the electronic configuration that is the same with the nearest noble gas.
1. Potassium's nearest noble gas is Ar which is one electron fewer. So, when ionized, it donates 1 electron. Hence, K⁺.
2. The nearest noble gas for fluorine is Neon which is 1 electron more. Hence, it has to accept one more electron. Hence, F⁻.