Вы можете добавить эту функцию в ViewDidLoad
- (void) setRightNavView
{
// Заменить titleView
CGRect headerTitleSubtitleFrame = CGRectMake(260, 0, 60, 44);
UIView* _headerTitleSubtitleView = [[UILabel alloc] initWithFrame:headerTitleSubtitleFrame];
_headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
_headerTitleSubtitleView.autoresizesSubviews = YES;
CGRect titleFrame = CGRectMake(0, 2, 60, 20);
UILabel *titleView = [[UILabel alloc] initWithFrame:titleFrame];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:12];
titleView.textAlignment = NSTextAlignmentCenter;
titleView.textColor = [UIColor blackColor];
titleView.text = @"Balance";
titleView.adjustsFontSizeToFitWidth = YES;
[_headerTitleSubtitleView addSubview:titleView];
CGRect subtitleFrame = CGRectMake(0, 22, 60, 22);
UILabel *subtitleView = [[UILabel alloc] initWithFrame:subtitleFrame];
subtitleView.backgroundColor = [UIColor clearColor];
subtitleView.font = [UIFont boldSystemFontOfSize:15];
subtitleView.textAlignment = NSTextAlignmentCenter;
subtitleView.textColor = [UIColor redColor];
subtitleView.text = @"sdfs";
subtitleView.adjustsFontSizeToFitWidth = YES;
[_headerTitleSubtitleView addSubview:subtitleView];
_headerTitleSubtitleView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[self.navigationController.navigationBar addSubview:_headerTitleSubtitleView];
}
, затем вы можетеустановите эту функцию в любом месте:
-(void) setBalanceTop:(NSString*)balance{
//NSArray *arrView = self.navigationController.navigationBar.subviews;
//NSLog(@"So view con: %d", (int)arrView.count);
//NSLog(@"Desc: %@", arrView.description);
// Индекс здесь зависит от того, сколько у вашего Naviga Controller субвидов
if([self.navigationController.navigationBar.subviews objectAtIndex:2] != nil){
UIView* balanceView = [self.navigationController.navigationBar.subviews objectAtIndex:2];
UILabel* titleView = [balanceView.subviews objectAtIndex:1];
NSLog(@"Type class: %@", [titleView description]);
if((titleView != nil) && ([titleView isKindOfClass:[UILabel class]]))
titleView.text = balance;
}
}