views:

48

answers:

1
CGRect frame = CGRectMake(10.0, 30.0, 32.0, 29.0);
UIImage *buttonImage = [UIImage imageNamed:@"visit_icon.png"];
UIButton *stopButton = [[UIButton alloc] initWithFrame:frame];
[stopButton setTitle:@"Button" forState:UIControlStateNormal];
[stopButton setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
[stopButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
stopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
stopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[stopButton addTarget:self action:@selector(stopAction:) forControlEvents:UIControlEventTouchUpInside];

i was adding button to my root view controller is not working may be i need to add this as a sub view to my view how can i do that?

A: 

You are on the right track.

Do this in the UIViewController subclass, at the end of your code above:

[self.view addSubview: stopButton];
Chris Cooper
yes ,but how can i add button at bottom tab bar
lak in iphone
how can i remove an image from my main view is added as sub view previously...
lak in iphone
`[stopButton removeFromSuperview];`
Chris Cooper