iOS 图表,删除底部由 xAxis 标签创建的额外 space
iOS Charts, Remove extra space created by xAxis Labels at bottom
我有一个用 iOS 图表创建的垂直垂直条形图。我的问题是,出于某种原因,每当我 运行 程序时,图表都不会从上到下填满它所在的视图。 我特别想修复一个小 space 栏底部和 UIView 底部之间的事实。我怎样才能删除这个 space 使栏的底部与 UIView 的底部完全对齐? (不需要间隙)
这是我的代码:
barChartView.xAxis.labelPosition = .top
barChartView.xAxis.drawGridLinesEnabled = false
barChartView.xAxis.drawAxisLineEnabled = false
barChartView.leftAxis.drawGridLinesEnabled = false
barChartView.leftAxis.drawAxisLineEnabled = false
barChartView.rightAxis.drawAxisLineEnabled = false
barChartView.rightAxis.drawGridLinesEnabled = false
barChartView.rightAxis.enabled = false
barChartView.leftAxis.enabled = false
barChartView.xAxis.labelTextColor = UIColor.white
barChartView.data?.setDrawValues(false)
barChartView.xAxis.labelFont = UIFont(name: "HelveticaNeue-Bold", size: 12.0)!
barChartView.legend.enabled = false
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:xValues)
barChartView.xAxis.granularity = 1
barChartView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0, easingOption: .easeInQuint)
barChartView.isUserInteractionEnabled = false
barChartView.barData?.barWidth = 0.65
这是问题的图片...我需要去掉条形底部和红色之间的间隙 space。图形所在的 UIView(与红色视图不同)向下延伸到红色视图的边框。
试试这个:
barChartView.minOffset = 0.0
如果这不起作用,也添加它。
barChartView.extraBottomOffset = -10
I can't discover special options in BarChartView
to resolve your problem. But I can suggest another way. You can embed your barChartView
into another view and set a vertical space constraint from between bottom of your barChartView
to bottom a superview with a negative value, also set clipToBounds = true
for the superview. So the bottom of barChartView
will be below the bottom of superview and will be cut.
View after embedding (yellow background - superview, white - barChartView).
View after bottom constraint was set to -14.
能够根据 phone 显示的大小以编程方式调整底部约束来解决我的问题。
我将此代码添加到 viewWillAppear 中,我将继续对其余 iPhone 尺寸执行此操作,而不仅仅是 Xs:
if UIScreen.main.bounds.height == 896{
print("Xs Max")
bottomConstraintGraph.constant = -31.5 // bottomConstraintGraph is the constraint connected from the bottom of the graph's view to the superview and changed here through an outlet connection.
}
我有一个用 iOS 图表创建的垂直垂直条形图。我的问题是,出于某种原因,每当我 运行 程序时,图表都不会从上到下填满它所在的视图。 我特别想修复一个小 space 栏底部和 UIView 底部之间的事实。我怎样才能删除这个 space 使栏的底部与 UIView 的底部完全对齐? (不需要间隙)
这是我的代码:
barChartView.xAxis.labelPosition = .top
barChartView.xAxis.drawGridLinesEnabled = false
barChartView.xAxis.drawAxisLineEnabled = false
barChartView.leftAxis.drawGridLinesEnabled = false
barChartView.leftAxis.drawAxisLineEnabled = false
barChartView.rightAxis.drawAxisLineEnabled = false
barChartView.rightAxis.drawGridLinesEnabled = false
barChartView.rightAxis.enabled = false
barChartView.leftAxis.enabled = false
barChartView.xAxis.labelTextColor = UIColor.white
barChartView.data?.setDrawValues(false)
barChartView.xAxis.labelFont = UIFont(name: "HelveticaNeue-Bold", size: 12.0)!
barChartView.legend.enabled = false
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:xValues)
barChartView.xAxis.granularity = 1
barChartView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0, easingOption: .easeInQuint)
barChartView.isUserInteractionEnabled = false
barChartView.barData?.barWidth = 0.65
这是问题的图片...我需要去掉条形底部和红色之间的间隙 space。图形所在的 UIView(与红色视图不同)向下延伸到红色视图的边框。
试试这个:
barChartView.minOffset = 0.0
如果这不起作用,也添加它。
barChartView.extraBottomOffset = -10
I can't discover special options in BarChartView
to resolve your problem. But I can suggest another way. You can embed your barChartView
into another view and set a vertical space constraint from between bottom of your barChartView
to bottom a superview with a negative value, also set clipToBounds = true
for the superview. So the bottom of barChartView
will be below the bottom of superview and will be cut.
View after embedding (yellow background - superview, white - barChartView).
View after bottom constraint was set to -14.
能够根据 phone 显示的大小以编程方式调整底部约束来解决我的问题。
我将此代码添加到 viewWillAppear 中,我将继续对其余 iPhone 尺寸执行此操作,而不仅仅是 Xs:
if UIScreen.main.bounds.height == 896{
print("Xs Max")
bottomConstraintGraph.constant = -31.5 // bottomConstraintGraph is the constraint connected from the bottom of the graph's view to the superview and changed here through an outlet connection.
}