A design optimization method applicable to both rarefied and continuum gas flows with good efficiency is proposed in the framework of gas-kinetic theory. The method follows the methodology of topology optimization where the areas of gas and solid are marked by the material density, based on which a fictitious porosity model is used to reflect the effect of the solid on the gas and mimic the diffuse boundary condition on the gas-solid interface. The formula of this fictitious porosity model is modified to make the model work well from the free-molecular flow regime to the continuum flow regime. To find the optimized material density, a gradient-based optimizer is adopted and the design sensitivity is obtained by the continuous adjoint method. To solve the primal kinetic equation and the corresponding adjoint equation, efficient multiscale numerical schemes are constructed. Several airfoil optimization problems are solved to demonstrate the performance of the present design optimization method in wide ranges of flow speed and gas rarefaction. It is found that the thickness of the optimized airfoil first increases and then decreases as the Knudsen number increases, and on the supersonic condition the optimized airfoil has quite different shapes of leading edge for different degrees of gas rarefaction.