Я пытаюсь разместить UIB-кнопку с изображением над моим UITabBar.
Я добавил этот код в метод applicationDidFinishLaunching, но получаю некоторые ошибки, когда tabBar
не распознается.
Я собрал TabBarController и NavController в IB.
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"addTabButton.png"];
UIImage *highlightImage = [UIImage imageNamed:@"addTabButtonHighlight.png"];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
button.center = self.tabBar.center;
else
{
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
button.center = center;
}
[self.view addSubview:button];
Редактировать:
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"addTabButton.png"];
UIImage *highlightImage = [UIImage imageNamed:@"addTabButtonHighlight.png"];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(btnTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:button];