Wearable electrochemical sensors enable non-invasive and continuous physiological monitoring for daily health management and early diagnosis of chronic diseases. Fabric-based wearable sensors have attracted great interest due to their excellent flexibility, breathability, and seamless fit to the skin. However, controllable preparation of sensing active materials on fibers on fabrics is challenging. In this study, polyaniline sensing materials were prepared controllably on the surface of fabric fibers by combining in-fabric photolithography and controlled electrodeposition techniques. This method was able to ensure the high-performance pH sensing of polyaniline while maintaining the pore structure of the fabric. The experimental results show that the sensitivity of the polyaniline pH sensor deposited for 15min is 57. 87mV/pH, which is closest to the theoretical limit of sensitivity. In addition, the prepared pH sensors exhibited excellent stability, including reproducibility, anti-interference and long-time stability. The method provides a new perspective for the preparation of high-performance fabric-based wearable sensors, and the prepared polyaniline pH sensors have important application prospects in skin health monitoring and wearable biomedical applications.