Magnetic coils for specific requirements are widely used in modern quantum physics. In this study, a general analytical method of designing the shielded coils for generating an arbitrary axial magnetic field is proposed. The theoretical formula for an axial magnetic field generated by a single shielded coil is obtained and used to construct specific coils. The structural parameters of these coils are determined by fitting the theoretical formula with their specific requirements. The feasibility of this method is proved by realizing four concrete kinds of coils: uniform magnetic field generating coils, gradient magnetic field generating coils, asymmetrical uniform magnetic field generating coils, and parabolic magnetic field generating coils. The correctness of these theoretical results is demonstrated by both the finite element simulations and the relevant experimental results. Furthermore, the application of this method is of great significance for developing the quantum physics and quantum devices in future.