Thursday, May 30, 2013

UIButton UIButtonTypeCustom example in Objective C (iOS).

UIButton UIButtonTypeCustom

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 UIButtonTypeCustom example.
UIButton *buttonUserName = [UIButton buttonWithType:UIButtonTypeCustom];
buttonUserName.frame = CGRectMake(10, 10, 280, 20);
[buttonUserName setTitle:@"test" forState:UIControlStateNormal];
[buttonUserName setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[buttonUserName setEnabled:YES];
buttonUserName.userInteractionEnabled = YES;
[buttonUserName addTarget:self action:@selector(user:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:buttonUserName];

Example of [UIButton UIButtonTypeCustom].
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(x, y, width, height)];
[button setTitle:@"Button" forState:UIControlStateNormal];
// Set visible values
[button setBackgroundColor:[UIColor greenColor]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[someSuperview addSubview:button];

UIButton UIButtonTypeCustom example.
UIButton *test = [UIButton buttonWithType:UIButtonTypeCustom];
test.frame = CGRectMake(30, 30, 49, 49);

End of UIButton UIButtonTypeCustom example article.