Customizing Scale Labels
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview of customizing scale labels on the IGLinearGaugeView™ control and demonstrates how to configure it using a code example.

In this topic


Introduction

Custom labels summary

The scale labels on the IGLinearGaugeView control are extremely flexible allowing you to present some highly specialized information via customization using the control’s linearGaugeView:formatStringForValue: delegate method. The method provides the IGLinearGaugeView calling the method with the label value to format and returns an NSString containing the text of the new label.


Customizing Scale Labels – Code Example

Description

The code example uses the IGLinearGaugeViewDelegate to implement the linearGaugeView:formatStringForValue: delegate method for adding a percent symbol to the label formatting.

Prerequisites

This code example requires the inclusion of the Chart framework; details about how to add this framework are available in the Adding the Chart Framework File topic.

Preview

Code

In Objective-C:

@interface igViewController () <IGLinearGaugeViewDelegate>
@end
@implementation igViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect gaugeRect = self.view.bounds;
    gaugeRect.size.height = 250;
    gaugeRect.origin.y = (self.view.bounds.size.height / 2) - 125;
    IGLinearGaugeView *gauge = [[IGLinearGaugeView alloc] initWithFrame:gaugeRect];
    gauge.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
    gauge.fontBrush = [[IGBrush alloc] initWithR:0 andG:0 andB:0 andA:1];
    gauge.interval = 20;
    gauge.value = 82;
    gauge.delegate = self;
    [self.view addSubview:gauge];
}
- (NSString *)linearGaugeView:(IGLinearGaugeView *)linearGaugeView formatStringForValue:(double)labelValue
{
    return [NSString stringWithFormat:@"%.0f%%", labelValue];
}
@end

In C#:

public partial class LinearGaugeScaleLabels_CSViewController : UIViewController
{
      public LinearGaugeScaleLabels_CSViewController ()
      {
      }
      public override void ViewDidLoad ()
      {
            base.ViewDidLoad ();
            
            RectangleF gaugeRect = this.View.Bounds;
            gaugeRect.Height = 250;
            gaugeRect.Y = (this.View.Bounds.Height / 2) - 125;
            IGLinearGaugeView gauge = new IGLinearGaugeView ();
            gauge.Frame = gaugeRect;
            gauge.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin;
            gauge.FontBrush = new IGBrush (UIColor.Black);
            gauge.Interval = 20;
            gauge.Value = 82;
            gauge.Delegate = new LinearGaugeDelegate ();
            this.View.Add (gauge);
      }
}
public class LinearGaugeDelegate : IGLinearGaugeViewDelegate
{
      public override string ResolveFormatString (IGLinearGaugeView linearGaugeView, double labelValue)
      {
            return String.Format ("{0}%", labelValue);
      }
}

Related Content

Topics

The following topic provides additional information related to this topic.

Topic

Purpose

The topics in this group cover enabling, configuring, and using the IGLinearGaugeView control’s supported features.