Thursday, May 30, 2013

UIButton UIButtonTypeRoundedRect example in Objective C (iOS).

UIButton UIButtonTypeRoundedRect

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 UIButtonTypeRoundedRect example.
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 30);

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor colorWithHue:1.0/12 saturation:2.0/3 brightness:4.0/10 alpha:1.0];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setLeftBarButtonItem:button animated:YES];

Example of [UIButton UIButtonTypeRoundedRect].
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;   
b. frame = CGRectMake(0, 0, 100, 100);

[b setTitle:@"Testing" forState:UIControlStateNormal];
[b setTitleColor: [UIColor blackColor] forState: UIControlStateNormal];
[self addSubview:b];

UIButton UIButtonTypeRoundedRect example.
UIButton *b=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
b=[UIButton buttonWithType:UIButtonTypeRoundedRect];

[b setTitle:@"Button Title Here" forState:UIControlStateNormal];
[b setTitleColor:[UIColor blackColor] forState: UIControlStateNormal];
[self.view addSubview:b];

End of UIButton UIButtonTypeRoundedRect example article.