Thursday, May 30, 2013

UIButton UIButtonTypeDetailDisclosure example in Objective C (iOS).

UIButton UIButtonTypeDetailDisclosure

Specifies the style of a button.

typedef enum {
UIButtonTypeCustom = 0,
UIButtonTypeRoundedRect,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
} UIButtonType;

Constants
UIButtonTypeCustom
No button style.
UIButtonTypeRoundedRect
A rounded-rectangle style button.
UIButtonTypeDetailDisclosure
A detail disclosure button.
UIButtonTypeInfoLight
An information button that has a light background.
UIButtonTypeInfoDark
An information button that has a dark background.
UIButtonTypeContactAdd
A contact add button.

UIButton UIButtonTypeDetailDisclosure example.
#import 

UIButton* btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSString* info = @"foobar";
objc_setAssociatedObject(btn, "info", info, OBJC_ASSOCIATION_RETAIN);
//Later somewhere
NSString* btnInfo = (NSString*)objc_getAssociatedObject(btn, "info");

Example of [UIButton UIButtonTypeDetailDisclosure].
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{

MKPinAnnotationView *mypin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"current"];
mypin.pinColor = MKPinAnnotationColorPurple;
mypin.backgroundColor = [UIColor clearColor];
UIButton *goToDetail = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mypin.rightCalloutAccessoryView = myBtn;
mypin.draggable = NO;
mypin.highlighted = YES;
mypin.animatesDrop = TRUE;
mypin.canShowCallout = YES;
return mypin;
}

UIButton UIButtonTypeDetailDisclosure example.
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id )annotation {    
    MKAnnotationView* ann = nil;   
    if(annotation != mapView.userLocation)
    {
        ann = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];   
        ann.canShowCallout = YES;   
        ann.image = [UIImage imageNamed:@"arrow.png"];       
        UIButton* butt = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];   
        [butt addTarget:self action:@selector(displayArrow:) forControlEvents:    
        UIControlEventTouchUpInside];       
        ann.rightCalloutAccessoryView = butt;   
    }
    return ann;
}

End of UIButton UIButtonTypeDetailDisclosure example article.