2012-06-28 4 views

답변

2

기본 제공 방법이 없습니다. 아래는 꽤 잘 나가 유래에서 함께 넣어 작동 여기 UINavigationItem with prompt and activity indicator

를 게시 할 것 같다 주위에 작업이 생성 무엇을 시뮬레이터 스크린 샷입니다 : iPhone screen shot of two line UINavigationItem prompt

참고 그 텍스트는 UILabel 때문에 당신 그것의 색깔, 글꼴, 또는 다른 것을 역시 수정할 수있다. 그 폭이 하드 코딩 할 필요가 없었어요 그래서

// I have this code in viewDidLoad 
UIView      *viewContainingPrompt; 
UIBarButtonItem    *promptButtonItem; 

// Configuring the prompt title of the navigation bar so it is present but empty 
[self.navigationItem setPrompt: @""]; 

// We will create a UIBarButtonItem that has a custom view (viewContainingPrompt). 
// A subview of viewContainingPrompt will be a UILabel (headerLabel) 
// We need to have this "intermediate" view to position the label at the right position 
// (the UIBarButtonItem ignores the origin and height of its custom view) 
viewContainingPrompt = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 0, 85)]; 
viewContainingPrompt.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

// Choose a width that puts 10 points on either end... 
CGFloat labelWidth = self.navigationController.navigationBar.bounds.size.width - 20.0; 
// Note that the '-60' below is determined by the width of the back button 
// If someone can figure out how to determine this width at runtime this code 
// would be much more robust. 
UILabel *headerLabel = [[UILabel alloc] initWithFrame: CGRectMake(-60,-8,labelWidth,36)]; 
headerLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
headerLabel.text = @"A quite long prompt string that will wrap to a second line to demonstrate multiline prompt."; 
headerLabel.font = [UIFont systemFontOfSize: 14]; 
headerLabel.numberOfLines = 0; // Zero gives as many lines as will fit, could be 2 
headerLabel.backgroundColor = [UIColor clearColor]; 
headerLabel.textColor = [UIColor colorWithRed: .1 green: .1 blue: .2 alpha: 0.8f]; 
headerLabel.shadowColor = [UIColor colorWithRed: 1 green: 1 blue: 1 alpha: 0.5f]; 
headerLabel.shadowOffset = CGSizeMake(0, 1); 
headerLabel.textAlignment = UITextAlignmentCenter; 
[viewContainingPrompt addSubview: headerLabel]; 
//[headerLabel release]; // Uncomment if not using ARC 

promptButtonItem = [[UIBarButtonItem alloc] initWithCustomView: viewContainingPrompt]; 
self.navigationItem.leftBarButtonItem = promptButtonItem; 
self.navigationItem.leftItemsSupplementBackButton = YES; 
//[viewContainingPrompt release]; // Uncomment if not using ARC 
//[promptButtonItem release]; // Uncomment if not using ARC 

나는 실행 중에 뒤로 버튼의 폭을 파악하는 방법에 대한 다른 사람의 의견을 보내 주셔서 감사합니다.

개인용 API 또는 기타 불법 코드가 포함되어 있다고 생각하지 않습니다.

관련 문제