In this study, we analyze the codebook design used for analog beamforming. Analog beamforming and combining suffer from a subspace sampling limitation, that is, the receiver cannot directly observe the channel coefficients; instead, the receiver observes a noisy version of their weighted combination. To resolve this, the transmitter and the receiver usually collaborate to determine the best beamformer combiner pair during the beam-sweeping process. This is done by evaluating a limited number of codewords chosen from a pre-defined codebook. In this study, we propose a new framework inspired by the generalized Lloyd algorithm to design analog beamforming codebooks that optimize various performance metrics including the average beamforming gain, the outage, and the average data rate. The flexibility of our framework enables us to design beamforming codebooks for any array shapes including uniform linear and planar arrays. The other practical complexity in analog beamforming is the low resolution of the phase shifters. Therefore, we have extended our algorithm to create quantized codebooks that outperform the existing codebooks in literature. We have also provided extensive simulations to verify the superiority of our proposed codebook as compared with the existing codebooks.