ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.5k stars 5.98k forks source link

background color is wrong when compiling with Xcode 9.0 #2837

Open kscheff opened 6 years ago

kscheff commented 6 years ago

I just recompiled my project using Charts 3.0.4. I did not change the Storyboard nor did I ever changed programmatically the background color of my CombinedChartView. Suddenly the background gets white (the color of the main view), my nice sky blue color of the CombinedChartView view is gone.

I checked to set the color to .clear after .initialize() but this results in a wired flashing black color. The only fix so far is that I explicitly set the background color to the desired value.

The same App previously compiled with Xcode 8 runs fine under iOS 11.

Update: just verified with iOS 10 same issue.

liuxuan30 commented 6 years ago
        #if os(iOS)
            self.backgroundColor = NSUIColor.clear
        #endif

It's always .clear by default on iOS. I don't remember we change it. Where do you set your sky blue color in the first place? Seems weird as well. What's the last version you use of Charts? Have you searched the keyword in your project?

kscheff commented 6 years ago

@liuxuan30 Originally I did not explicitly set the .backgroundColor. I defined the Sky Blue in the CombinedChartView Storyboard background color. I stepped through with the debugger and see that the self.backgroundColor = NSUIColor.clear is called inside the framework. As described the result is a white background which corresponds to the parent View the CombinedChartView is embedded in. Channing the parent View color changes the background of the chart.

Next I tried to set the .clear color explicitly right after calling .initialize(). The result is a flashing black background in the chart. Only setting a non-clear color the background appears OK. I also tried to set the color to UIColor.clear rather than to NSUIColor.clear - no change.

At the moment I gave up and use the workaround setting the desired color right after .initialize().

kscheff commented 6 years ago

In order to explore the situation I have quickly added some properties so I can set the background color directly in Storyboard. Using my own subclass of CombinedChartView and changed the View Class inside Storyboard from CombinedChartView to MyChartView (don't forget to tick Inherit Module From Target) allows for modification without messing inside the Charts framework.

@IBDesignable
class MyChartView: CombinedChartView {
  override func initialize() {
    super.initialize()
    self.backgroundColor = backColor
  }

  @IBInspectable var backColor: UIColor? {
    didSet {
      self.backgroundColor = backColor
    }
  }

}

Side note: further exploring these feature would be a nice enhancement to this framework, so more features could be modified directly from Storyboard...