Я создал пользовательскую вкладку и добавил пользовательское изображение в центральном положении. Следующий код работает так, как ожидалось. Он добавляет мою настраиваемую кнопку в центр панели вкладок.Скрыть пользовательскую кнопку ToolBar
CustomTabBarViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage* buttonImage = [UIImage imageNamed:@"icon_floating.png"];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
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;
}
[button addTarget:self
action:@selector(myAction)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void) myAction
{
self.selectedIndex = 2;
}
Вопрос, который я столкнулся следующим образом. Существует viewcontroller - ChatViewContoller
где я скрываю tabbar
. Но так как пользовательская кнопка добавляется в tabbar
, я не смог скрыть пользовательскую кнопку со следующим кодом.
ChatViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
CustomTabBarViewController* tab = [[CustomTabBarViewController alloc] init];
tab.button.hidden = YES;
}
Попробуйте использовать существующую панель инструментов в режиме viewvidload chatVC – sanman