Talk with a healthcare professional
Insomnia and other sleep issues are not something you have to handle on your own. To control UC symptoms and improve your quality of sleep, a medical expert can advise you on lifestyle modifications and, if necessary, prescribe medications.
For instance, if you wake up at night with cramps or abdominal pain, your doctor may advise you to take a painkiller like an acetaminophen. Or they could suggest an antispasmodic to treat your cramps. A doctor might also advise taking an antidiarrheal medication before bed if you worry about a bathroom emergency keeping you up at night, particularly if you had a big meal or had dinner somewhere else. In general, you might find this useful to keep track of your UC symptoms, especially those that interfere with your sleep, so you can talk to a doctor about them. Then mutually come up with a solution after identifying the cause of what's keeping you up at night.