tags:

views:

1859

answers:

3
+3  A: 

If you are adding a new view, you should be sure to set the frame property to a position and width and height that will not cause it to be bigger than it should.

Like so:

myNewView.frame = CGRectMake(x, y, width, height);

At least it looks like your new view is bigger than it is supposed to be. Also, be sure to draw only within those bounds, adding things outside the range of your view can cause problems.

Kekoa
That was it :) Thx a lot.
Mladen
A: 

I'm writing the exact same thing right now. My problem is that the segmented control is unclickable.


#import "DateLinePlotView.h"


@implementation DateLinePlotView

@synthesize xLabels;
@synthesize yValues;
@synthesize graphView;  


- (id) init
{
    if (self = [super init]) 
    {
     // Set up the graph view
      self.graphView = [[S7GraphView alloc] initWithFrame: CGRectMake(-20, 60, 380, 300)];
      self.graphView.dataSource = self;
      [self addSubview: graphView];

      self.xLabels = [[NSMutableArray alloc] init];

      [xLabels addObject: @"One"];
      [xLabels addObject: @"Two"];
      [xLabels addObject: @"Three"];

      self.yValues = [[NSMutableArray alloc] init];

      [yValues addObject: [NSNumber numberWithInt: 3]];
      [yValues addObject: [NSNumber numberWithInt: 8]];
      [yValues addObject: [NSNumber numberWithInt: 3]];

     // Set up the segment control
      NSArray *segmentTextContent = [NSArray arrayWithObjects: @"All", @"Year", @"Month", nil];
      UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
      segmentedControl.frame = CGRectMake( kLeftMargin,
                340 + kTweenMargin + 20,
                282,
                kSegmentedControlHeight);
      [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
      segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
      segmentedControl.selectedSegmentIndex = 1;
      segmentedControl.enabled = true;

      [self addSubview:segmentedControl];
      [segmentedControl release];
    }
    return self;
}


- (void)dealloc 
{
    [xLabels release];
    [yValues release];
    [graphView release];

    [super dealloc];
}


#pragma mark -
#pragma mark S7GraphViewDataSource methods
- (NSUInteger)graphViewNumberOfPlots:(S7GraphView *)graphView 
{
/* Return the number of plots you are going to have in the view. 1+ */
    return 1;
}

- (NSArray *)graphViewXValues:(S7GraphView *)graphView 
{
/* An array of objects that will be further formatted to be displayed on the X-axis.
   The number of elements should be equal to the number of points you have for every plot. */

   return xLabels;
}

- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex 
{
/* Return the values for a specific graph. Each plot is meant to have equal number of points.
   And this amount should be equal to the amount of elements you return from graphViewXValues: method. */

   return yValues;
}




- (void)segmentAction:(id)sender
{
    NSLog(@"segmentAction: selected segment = %d", [sender selectedSegmentIndex]);
}




@end

sam
A: 

Is it possible that you publish the complete source code. I just started using s7graphview and really like the way your project looks.

Thx