hello, I have a simple view consists of a graph and a legend below it. For simplicity I have highlighted in red the frame of the legend The problem is that values are centered, but remain aligned in the upper right Below I put the code and an image:
IGChartView *grafico = [[IGChartView alloc] init]; grafico.translatesAutoresizingMaskIntoConstraints = NO; grafico.delegate = self; [self.view addSubview:grafico];
IGLegend *legend = [[IGLegend alloc] initWithLegendType:IGChartLegendTypeSeries]; legend.translatesAutoresizingMaskIntoConstraints = NO; legend.orientation = IGOrientationHorizontal; legend.horizontalAlignment = IGHorizontalAlignCenter; legend.verticalAlignment = IGVerticalAlignCenter; legend.backgroundColor = [UIColor redColor]; grafico.legend = legend; [self.view addSubview:legend];
//Constraints NSDictionary *views = NSDictionaryOfVariableBindings(grafico,legend); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[grafico]|" options:0 metrics:nil views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[legend]|" options:0 metrics:nil views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[grafico][legend(50)]|" options:0 metrics:nil views:views]];
Hi Mattia,
The problem has been fixed and is currenly undergoing testing for future service release.I just wanted to let you know that if you need a workaround that still uses layout constraints you can do the following:Create a custom legend that derives from IGLegend and override setBounds. Something like this:
@interface CustomLegend : IGLegend@end
@implementation CustomLegend-(void)setBounds:(CGRect)bounds{ [super setBounds:bounds]; [self updateItems];}@end
You would then replace your IGLegend with CustomLegend and the alignment will work properly