It isn't easy, but is certainly sometimes a valid defense. If the conditions in your apartment are bad enough to make the unit unlivable, or expose you to a clear and present danger, it is possible to discontinue your lease obligations and not be responsible for rent charges under the remaining term. You have in effect been "constructively evicted" by the landlord's unconscionable lack of service.
But even if conditions necessitate your leaving, you can expect your landlord to sue you for the rent due under the balance of the lease. To be released from that obligation, you will need to prove that the premises were uninhabitable or dangerous. Take pictures before you leave, keep a file of all written complaints and a record of phone calls to the landlord, as well as any other supporting documentation you can obtain from neighbors.
Also have any police or other government agency investigative reports. Leaks, flooding, environmental hazards such as lead paint or asbestos, non-working elevators, unbearable odors, and drug dealer activity are all potential reasons to vacate and to possibly claim "constructive eviction."