2013-09-20 2 views
0

Я создаю приложение, которое каждые 5 минут получает новые данные с сервера. Я хочу уведомить пользователя о количестве новых данных, добавленных в его предыдущие. Я использую панель инструментов, и я хочу показать этот значок в определенном месте. см. код i:iphone добавить значок уведомления в uitoolbar

// notification button 
UIButton *notifications=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
notifications.bounds = CGRectMake(40, 34, 20,20); 
[notifications setTitle:@"1" forState:UIControlStateNormal]; 
notifications.backgroundColor = [ UIColor clearColor]; 
[notifications addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 


// add to uibutton 
UIBarButtonItem *notify = [[UIBarButtonItem alloc] initWithCustomView:notifications]; 

items = [NSArray arrayWithObjects: add, search,flexItem,currentLoc,notify,logoLabel, nil]; 

но кнопка не отображается в объявленном месте (40,30) ,, любая помощь?

ответ

0

Вам необходимо пройти UIButton как:

// notification button 
UIButton *notifications=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
notifications.bounds = CGRectMake(40, 34, 20,20); 
[notifications setTitle:@"1" forState:UIControlStateNormal]; 
notifications.backgroundColor = [ UIColor clearColor]; 
[notifications addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 

// Pass your button in UIBarButtonItem here 
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:notifications]; 
[toolBar setItems:[NSArray arrayWithObject:barButton]]; 

Надеется, что это помогает.

+0

Я сделал это, но я не добавил полный код, когда задаю вопрос, я обновил вопрос – etab

+0

кнопка уведомления отображается точно до того, как «логотип» не согласован в координате – etab

+0

, потому что эта последовательность кнопок будет подобно тому, как вы прошли. Если вам нужно отобразить его в другом месте, измените порядок массива. –

Смежные вопросы