There is no contradiction between the two matters. Allah تعالى is the Creator and the One who grants males and females. He says:
﴿He grants female children to whom He wills, and He grants male children to whom He wills or He gives them both males and females, and He makes whom He wills infertile.﴾ [Ash-Shura: 49–50]
However, part of His wisdom is that He has established causes for created things, while the cause does not independently produce an effect. Rather, its effect occurs by the will of Allah تعالى. Allah is the One who heals, and He has made medicine a means of healing. He is the Provider, and He has made work and earning means of obtaining provision. He is the Creator of human beings, and He has made marriage a means of having children. Likewise, He may make certain methods have an effect in favoring one sex of the fetus over the other, without this meaning that these methods act independently or contradict His decree.
Therefore, Islam takes a middle position between those who completely deny causes and those who believe that causes produce effects by themselves. A cause produces its effect only by the will of Allah تعالى, and a person may take the available means without obtaining what he wanted.
The basic principle is that a Muslim should be content with whatever child Allah decrees for him, whether male or female, and should not attach his heart to the means. What is promoted as methods for determining the sex of a child is not all legitimate or correct. Some of it consists of myths and superstition, some involves prohibited matters, and some has not been scientifically established.
As for natural methods that do not involve anything prohibited by Islamic law, such as diet or timing intercourse, the Islamic Fiqh Council has permitted them on the basis that they are permissible means. As for medical intervention to select the sex of the fetus, it is not permissible merely because of personal preference. An exception is made when there is a therapeutic necessity, such as the risk of transmitting certain genetic diseases that affect one sex but not the other, subject to the established Islamic and medical guidelines.
Accordingly: It is permissible to use permissible means while believing that Allah تعالى alone is the Creator and the One who determines all things, that the means do not guarantee the outcome, and that one must be content with what Allah تعالى decrees and place one's trust in Him.
And Allah تعالى knows best.