Hey guys,

Here I'll show you how to create UIButton programmatically.

Code:
UIButton *htmlCopy = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
	htmlCopy.frame = CGRectMake(246, 207, 71, 31);
	[htmlCopy setTitle:copybuttonstring forState:UIControlStateNormal];
	[htmlCopy setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	htmlCopy.backgroundColor = [UIColor clearColor]
	[htmlCopy addTarget:self action:@selector(EmailCopyEvent:) forControlEvents:UIControlEventTouchUpInside];
	[htmlCopy setBackgroundImage:[UIImage imageNamed:@"chrome.png"] forState:UIControlStateNormal];

Code explanation:

1)
Code:
 UIButton *htmlCopy = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
This will create the button with type "Custom", you can chose deferent types like rounded etc..

2)
Code:
 htmlCopy.frame = CGRectMake(246, 207, 71, 31);
This will define the location and size of button (x axes, y axes, width , height).

3)
Code:
 [htmlCopy setTitle:@"Set Title" forState:UIControlStateNormal];
Sets the title of the button.

4)
Code:
 [htmlCopy setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Sets the color of the title.

5)
Code:
 htmlCopy.backgroundColor = [UIColor clearColor];
Sets background color.

6)
Code:
 [htmlCopy addTarget:self action:@selector(EmailCopyEvent:) forControlEvents:UIControlEventTouchUpInside];
Sets an action for button.

7)
Code:
 [htmlCopy setBackgroundImage:[UIImage imageNamed:@"chrome.png"] forState:UIControlStateNormal];
Sets background image of button.