Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Doctor Q

Administrator
Original poster
Staff member
Sep 19, 2002
39,899
7,817
Los Angeles
I'm working on an iOS/iPadOS app that looks fine in the Xcode simulator but has a nasty difference when run on a real device.

For example, I set a UINavigationBar title on my Settings screen as follows:

Code:
self.navigationItem.title = "Settings"

Here's how the top of the iPad screen looks in the simulator:
simulator.png

Here's how it looks on a real iPad when connected to my Mac and run via the simulator:
simulator.png

And here's how it looks if I stop running the simulator and launch it independently on the iPad. As you can see, the black text gets a black background, making it unreadable.
ipad.png

Black text in a UITableView (on a white background) also turns to black-on-black and becomes unreadable. Example:
table view.png

UIButtons with the "Filled" style have white text on a blue background in the simulator, but running directly on the iPad they have white text with a black background, inside a frame of blue. Example in the simulator:
good button.png

On a real device:
bad button.png

Even some third-party custom views I'm using get black backgrounds.

I've tried running the app on each possible simulated device, and they all work correctly, as the app is designed to look. I've tried running the app on several real devices, and every one has the black background problem. Updating to the latest iOS/iPadOS didn't resolve it. I don't have any special "accessibility" settings turned on.

I've tried tinkering with the properties of these various views, like changing background colors from Default to Clear, but no change of properties makes the behavior change.

Any ideas?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,806
8,546
A sea of green
I'm only going to run through some troubleshooting ideas.


First, try switching the device to Dark Mode and see what happens.

Related to that, try some of the Accessibility settings regarding inverted colors, contrast, etc. You wrote that the Accessibility settings are turned off, so see what happens when you turn them on.


Second, try adding a completely new button or label to the view. Make sure it's not using any presets or inheritance from any other component. In other words, make sure it's completely new.

I mention this because if there's some inheritance or replication going on, then the real cause of the problem could be another component either up the view tree, or something that's serving as a prototype or template that other components of the same type are copied from.

How old is this app project in Xcode? That is, what versions of Xcode have been used to edit it in the past?

It could be that some incompatibility crept in at some point, or Xcode itself bungled something as newer versions were used.


Third, set the color of the text to something other than white, like maybe red. Is the background still black?

I'm asking because black is the opposite of white, so if the background for red text is the opposite of red, then that's a different clue than always getting a black background.


Fourth, try making a completely new but trivial app, that only has a view with a label and a button, or other trivial controls.

If that new app displays correctly on the device, then the problem is with some setting or configuration in the original app.


Finally, the black area looks like it's just the background of the text itself, as distinct from any component that has a textual sub-component. I think this is still called the "bounding box" of the text, but it's been awhile, so maybe that like "the bee's knees".


Oh, and exactly which OS version is this running under on the iPad?
And which Xcode version, on which OS?
 

Doctor Q

Administrator
Original poster
Staff member
Sep 19, 2002
39,899
7,817
Los Angeles
I did, but the package had insufficient postage so it was returned to me, and I ate all of the brownies before realizing they were for you.
 

Doctor Q

Administrator
Original poster
Staff member
Sep 19, 2002
39,899
7,817
Los Angeles
I used all of the suggestions above, which proved that the problem is unique to this project, affecting all buttons and certain other views. The project has some imported third-party code, so I disabled one component at a time to see if one of them might be the guilty party. Sure enough, one of them included a backgroundColor extension to UIView with a getter and a setter that looked harmless, but weren't in fact harmless. That extension is not needed, is now disabled, and the black backgrounds are gone at last! Thanks for the help.

For the record, I'm using Xcode 13.3, macOS12.3.1, and iPadOS 15.4.1.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.