Hi,
I've created some radial gauges inside of CGRect objects and I want the edge of each gauge to touch the sides of the rectangle.
The problem is that the backingShape is extending far beyond the edge of the "ticks" and everything else. So the backing is touching the sides of the box, but the useful part of the gauge is only about half the radius of the backing.
I've tried adjusting the backingOuterExtent value to less than 1, but this makes the backing smaller instead of the rest of the gauge bigger.
How do I push the rest of the gauge (ticks, labels, needle) out to the edge of the backing, so that the gauge is as large as possible for the space it's confined to?
Here's what I'm doing right now to get the effect I'm looking for (Swift 4):
let gauge = IGGaugeView.init(frame: CGRect.init(x: 0 - container.frame.size.width*0.3, y: 0 - container.frame.size.height*0.3, width: container.frame.size.width*1.6, height: container.frame.size.height*1.6)
gauge.autoresizingMask = [ UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleWidth ]
gauge.backingOuterExtent = 0.62
This is working. The backingExtent only slightly extends past the gauge ticks, and it completely fills the subview that it's embedded in. The problem with this is that the invisible part of the gauge extends quite a bit outside of the container, which might cause weird things to happen with touch events.
Is there a more elegant way to achieve this effect?
I think using extent properties will work best instead of changing the frame size. Reducing backing extent won't make other elements larger, but the gauge does have other extent properties that should help you. Things can get tricky if you're using a partial circle for the gauge, but hopefully that's not the case here. You can try something like this to push gauge elements towards the outer edge:
gauge.backingOuterExtent = 1;
gauge.labelExtent = .95;
gauge.tickStartExtent = .85;
gauge.tickEndExtent = .9;
gauge.scaleStartExtent = .8;
gauge.scaleEndExtent = .9;
gauge.minorTickStartExtent = .87;
gauge.minorTickEndExtent = .9;
gauge.needleEndExtent = .8;