Transmembrane proteins are inserted into the membrane in the ER in a rather complicated system, there is a whole chapter about translocation of proteins in "Molecular Biology of the Cell".
The proteins are moved through an aqueous pore in the Sec61 complex, which explains how charged parts of a protein are moved across the membrane.
The parts of a transmembrane protein that remain in the membrane are usually composed of hydrophobic amino acids that aren't charged.
I strongly recommend you to read up on the whole translocation stuff in a cell biology book like the Alberts I linked. There's a lot more to it than what I wrote here.