Thursday, May 30, 2013

UIButton UIButtonTypeContactAdd example in Objective C (iOS).

UIButton UIButtonTypeContactAdd

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 UIButtonTypeContactAdd example.
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(-100, 0, 420, 480)]; // start 100 pixels to the left
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    btn.frame = CGRectMake(0, 10, btn.bounds.size.width, btn.bounds.size.height);
    [myView addSubview:btn];

    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn1 setTitle:@"DoIt" forState:UIControlStateNormal];
    btn1.frame = CGRectMake(100, 100, 50, 50);
    [btn1 addTarget:self action:@selector(doit:) forControlEvents:UIControlEventTouchUpInside];
    [myView addSubview:btn1];
    self.view = myView;
}

Example of [UIButton UIButtonTypeContactAdd].
[super viewDidLoad];
offscreenView = [[UIView alloc] initWithFrame:CGRectMake(-100, 0, 200, 200)];
offscreenView.backgroundColor = [UIColor blueColor];
UIButton * btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
//note we put this at 10, 10 *relative to the button's superview*
btn.frame = CGRectMake(10.0, 10.0, 50.0, 25.0);
[btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[offscreenView addSubview:btn];
[self.view addSubview:offscreenView];
[UIView beginAnimations:@"animateVIew" context:self];
offscreenView.frame = CGRectMake(0.0, 0.0, 200, 200);
[UIView setAnimationDuration:2.0];
[UIView commitAnimations];

UIButton UIButtonTypeContactAdd example.
UIButton *contactAddButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[contactAddButton setUserInteractionEnabled:FALSE];
cell.accessoryView = contactAddButton;

End of UIButton UIButtonTypeContactAdd example article.