0

This iOS5+ project is using storyboard and ARC is ON.

I'm making a custom view with a 'circle' inside (which will reprent a click, that'll just be a backgroundimage) and I need to draw circle segments inside (which I'm already doing in my drawRect) that represent a timespan (it'll be clearer in the code).

Now thee timespans represent an event, that comes from the event array, holding Event items (also clearer in code)

Now what I WANT is to also draw buttons on top of the circlesegments, and these buttons need to be linked to certain events. (this could be as easy as to add an identifier to the buttons corresponding to an ID and when clicked open an annotation showing a title and a button. So basicly I want these buttons to behave like map annotations from the mapkit, and then be able to click the button and go the a detail page (which I've already made and which I'm using for my mapView) (I'd also like to use a custom image for these buttons)

How would I tackle this?

The filestructure for the important files of this quetion is:

Event.h
Event.m
RadarViewController.h
RadarViewController.m
RadarView.h
RadarView.m

The drawing of the clock happens in the drawRect of the RadarView.m In the storyboard there is a UIView with a class of RadarViewController and this has a subclass on top of it with a class of RadarView. It's the drawRect of the radarView which draws the clock (and there the drawRect function is implemented.)

I can access the events array by a singleton (will be clear in code.)

----- coding -----

This is my current drawRect function:

RadarView.m

- (void) drawRect:(CGRect)dirtyRect{
    CGRect bounds = [self bounds];
    CGPoint center;
    center.x = (bounds.origin.x + bounds.size.width)/2.0;
    center.y = center.x;

    // Set context being drawn upon
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] setStroke];
    CGContextAddArc(context, center.x, center.y, center.x, 0, 2*M_PI, YES);
    CGContextStrokePath(context);
    SingletonManager *sharedManager = [SingletonManager sharedManager];

    Event *tmp;
    double radius;
    double startRad;
    double endRad;


    if(currentLocation == nil){
        currentLocation = [sharedManager currentLocation].location;
    }

    for(int i = 0; i < [sharedManager.eventsManager count]; i++){
        tmp = [sharedManager.eventsManager objectAtIndex:i];
        CLLocation *loc = [[CLLocation alloc] initWithLatitude:tmp.coordinate.latitude longitude:tmp.coordinate.longitude];
        CLLocationDistance distance = [currentLocation distanceFromLocation:loc];
        if(distance>0){

            while(distance > 400.0){
                distance -= 400.0;
            }
            radius= distance / 400.0;
            radius *= center.y;
            [[UIColor redColor] setStroke];
            CGContextSetLineWidth(context, 5);
            CGContextSetAlpha(context, 0.6);

            startRad = [self getRadians:tmp.start];
            endRad = [self getRadians:tmp.einde];

            CGContextAddArc(context, center.x, center.y, radius, startRad, endRad, YES);
            CGContextStrokePath(context);
        }
    }
}

-- UPDATE --

Something I wanted to try in the RadarView was:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSLog(@"This is called <3");
        UIButton *btn= [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake(0, 0, 25, 25);
        btn.backgroundColor = [UIColor clearColor];
        [btn setTitle:@"test" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn]; 
    }
    return self;
}

But that doesn't work, it's not displaying

Spyral
  • 760
  • 1
  • 12
  • 33
  • Just add the buttons as subviews? Or have I missed the point? – jrturton Jul 20 '12 at 13:40
  • @jrturton These are dynamicly created? So not in the storyboard? I'm just new to 'coding' views, could you should me how I'd do that? and giving them an 'identifier' and how do I add an 'annotation' to them, etc? – Spyral Jul 20 '12 at 13:46
  • http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/addSubview: the rest of your comment is far too broad for an answer here. – jrturton Jul 20 '12 at 13:51
  • Lol serieously.. The UIView ref. You think I haven't checked that? How do you think I got the the point of the circlesegments -.- – Spyral Jul 20 '12 at 13:59
  • You're doing far too much in the drawRect method. – Abizern Jul 20 '12 at 14:26

0 Answers0