They actually explain it. Basically, her attitude comes from her rough past of isolation and struggle. She did poorly and school and felt alone in Opelucid City. She struggled to fit in, and she was away from her friends and Pokemon.
I think she acts like a know-it-all because she's overcompensating for her past issues, weak Axew, lazy Emolga and disobedient Excadrill. She acts rude and condescending because she wants to keep people at arm's length and snipe them before they can snipe her.
Once Ash showed his skill to her, and proved to be a loyal and patient friend, she cooled off a bit more, even going so far as to arrange that bizarre cheering thing in Roxie's Gym to make sure he gets all the support he needs. She really mellows out as the series goes on.
Essentially, she was bullied and knows she's kind of shit. Ash and Cilan support and be the friends that she needed, allowing her to grow and improve as a person.