Add image and text on button programmatically


Many times we have the requirements to add the button programmatically as well as to the text on that button when we set the image on the button then text will be not visible.so, in that case write the following code
start code and new project view based application or singleview application
then inlace of the viewDidLoad method write the following code then run the application
you will find the button with the image and with the text just click on the butto.
-(void)ButtonClicked
{
UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, 320, 410)];
[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://development-iphone-app.blogspot.com/"]]];
[self.view addSubview:wv];
}
- (void)viewDidLoad
{
UIButton *Btn = [UIButton buttonWithType:UIButtonTypeCustom];
[Btn setFrame:CGRectMake(10, 10, 300, 35)];
[Btn setBackgroundImage:[UIImage imageNamed:@"reviews.png"] forState:UIControlStateNormal];
[Btn setTitle:@"http://development-iphone-app.blogspot.com/" forState:UIControlStateNormal];
[Btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[Btn setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
[Btn addTarget:self action:@selector(ButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:Btn];
[super viewDidLoad];
}

1 comments:

Post a Comment

Powered by Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More