Apple is using the law, if lawmakers are not smart enough to create comprehensive tax laws, it's their fault not Apple's, however ...
Apple loves to paint itself as a "champion of goodness", a moral, caring, sensitive company ... in reality, they are as greedy and crafty as any other company, but they have the world convinced otherwise. Case in point, ask a young person who is the more evil/greedy company, Apple or Exxon, Apple or IBM, or Apple or Boeing. I bet every time the person would say Apple is not a greedy company, they have all those young, cool, hip, long hair, tattooed employees at their stores who wear cool Apple t-shirts and say dude a lot.
It's all crap, Apple price gouges its customers for a much as they can get away with and then they spend millions on tax lawyers and accountants to exploit every loophole they can find. All this while their public relations department convinces the world of their so-called altruism.
There's nothing wrong with a public corporation wanting to create as much profit for its stockholders as they can. You can call that 'greed', but I'd just say it's capitalism. Apple tries to maximize its profit within the letter of the law, but so does every other big corporation.
But there's a big difference between that 'greed' and being unethical or outright immoral. There are many companies that have gone that latter path, but I'd say Apple is still an ethical company, as evidenced by their dedication to improving their footprint on the environment, their dedication to making their products accessible to people of all levels of physical ability, and their dedication to protecting the privacy of users and not using this information to unethical ends.