Persuading someone to stop talking negatively isn't easy when it's all they do. They are obviously prone to look at the bad side of life, and they complain about things that are happening to them and not happening to them as well. But their negative talk can bring you down when you are trying to focus on positive things. They can be exhausting to listen to and undue all your positive work on yourself with one rant about how much life sucks. Changing how they talk around you boils down to convincing them of a few things.
First you want to show them that you don't agree with their views and complaints. I use this technique often with people when it comes to the weather. Many people will complain about the rain, sun, snow, ice, heat, cold, or whatever temperature it happens to be outside. Then they proceed to other complaints from there.
I stop them after their initial complaint by disagreeing with them. So, if they complain about how it's going to rain again I quickly cut them off and talk about how much I love the rain and how good it is for our plants and grass. They always quickly change their point of view to reflect mine and then either stop talking, walk away, or just change the subject.
If you keep disagreeing with any complaints they have they will eventually have nothing to complain about to you! Conversation will become lighter and more enjoyable with them, and chances are not only will you get the benefits of it but they will feel better and more positive as well.
Second you want to show them that you will not engage in their views by not engaging in the conversation any further. If they continue complaining about the weather after you have given your positive statement then just stop engaging in the conversation about weather with them altogether.
You can do this by changing the subject to something else, focusing your attention elsewhere and not responding, or just telling them that you don't want to talk about that subject. Most of the time they will stop talking about it if you give them these clear signals and they will either change the subject with you or move on to someone else.
Lastly you want to become someone who will not listen to their complaints continuously. If they are someone who just can't let go about how much the rain is going to suck, and you can't convince them to see it differently or talk about something different, then you may just want to get up and walk away. This is a direct message that you do not want to engage in that kind of conversation and they should get the hint from it.
Normally if you do this enough times with a persistent complainer they will stop complaining around you so that they can actually talk to you. They will associate their complaining with your leaving, and if they like you they will want to keep you around and conform to your more positive approach to communication.