В качестве конкретного примера того, что предлагает KennyTM, вы создаете UIBarButtonItem примерно следующим образом (в коде):
UILabel *txtLabel = [[UILabel alloc] initWithFrame:rect];
txtLabel.backgroundColor = [UIColor clearColor];
txtLabel.textColor = [UIColor lightGrayColor];
txtLabel.text = @"This is a custom label";
UIBarButtonItem *btnText = [[[UIBarButtonItem alloc] initWithCustomView:txtLabel] autorelease];
Затем вы можете добавить его в виде центрированного текста на панели UIToolbar (например,) со следующим:
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:rect];
toolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *flexSpace1 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
UIBarButtonItem *flexSpace2 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
[toolBar setItems:[NSArray arrayWithItems:flexSpace1, btnText, flexSpace2, nil]];
(конечно, чтобы получить правильное форматирование, rect
, используемый для инициализации txtLabel
и toolBar
, должны быть правильного размера .... но это еще одно упражнение!)