2013-05-14 2 views
2

나는 애플 대리자에서 다음과 같이 내 탐색 모음 수정 :제거 uinavigationbar 제목 마진

NSDictionary *settings = @{ 

          UITextAttributeFont     : [UIFont fontWithName:@"impact" size:36.0], 
          UITextAttributeTextColor   : [UIColor whiteColor], 
          UITextAttributeTextShadowColor  : [UIColor clearColor], 
          UITextAttributeTextShadowOffset  : [NSValue valueWithUIOffset:UIOffsetZero]}; 

[[UINavigationBar appearance] setTitleTextAttributes:settings]; 

을하지만 글꼴은 큰 글꼴이 같이 아래로 잘라냅니다. :

enter image description here

나는, 내 VC의 viewWillAppear에서이 일을 시도 :

UIView *newTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
[newTitleView setBackgroundColor:[UIColor blackColor]]; 
[self.navigationController.navigationBar addSubview:newTitleView]; 

그럼 내가 중심에 제목을 정렬하려고 했어요. 그러나 그것은 단지 옳은 것처럼 보입니다. 실제로 필요한 것은 제목 라벨의 상단과 하단에서 여백을 제거하는 것입니다. 어떻게해야합니까?

답변

3

이 코드를 사용해보십시오와 서브 클래스 사용자 정의 헤더보기로 이동하는 것이 좋습니다 및 setTitleTextAttributes을 설정하지 낭포 하위 뷰는 또한이 영향을 미칠 수

UILabel *titleView = (UILabel *)self.navigationItem.titleView; 
    if (!titleView) { 
     titleView = [[UILabel alloc] initWithFrame:CGRectZero]; 
     titleView.backgroundColor = [UIColor clearColor]; 
     titleView.font = [UIFont boldSystemFontOfSize:20.0]; 
     titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; 

     titleView.textColor = [UIColor yellowColor]; // Change to desired color 

     self.navigationController.navigationItem.titleView = titleView; 
     [titleView release]; 
    } 
    titleView.text = title; 
    [titleView sizeToFit]; 
+0

initWithFrame : CGRectZero ?? – CalZone

+0

유연한 너비를 제공해야합니다 ... 작동하지 않는 경우 [[UILabel alloc] initWithFrame : CGRectMake ([self.title length] <10? UITextAlignmentCenter : UITextAlignmentLeft), 0, 480,44) ]; titleLabel.backgroundColor = [UIColor clearColor]; – Divyu

+0

'self.navigationController.navigationItem.titleView = titleView;'어떻게 든 나를 위해 일하지 않습니다, 나는 [self.navigationController.navigationBar addSubview : titleView]; '를 사용했습니다. – CalZone

2

내가 제안하는 가장 쉬운 방법은 요구 사항에 맞게 사용자 정의 된 레이블 및 단추가있는 UIView를 사용하고 탐색 모음이 아닌 UI를 사용하는 것입니다. mnavigation 바 높이 정의는 높이가 고정되어있는 문제이며, 내가 UIView의

+0

사실,하지만 단 한 가지는 tweeked해야합니다. 거기에 수직 마진이 있기 때문에, 전체 펜촉 배치를 변경하는 대신 탐색 막대에서 할 수 있기를 바랬습니다. – CalZone

1

당신은 UILabel에 서브 클래스 화해, drawTextInRect을 무시할 수 있습니다 : 같은 : 더 유용한 링크를 들어

- (void)drawTextInRect:(CGRect)rect { 
    UIEdgeInsets insets = {0, 5, 0, 5}; 
    return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; 
} 

당신이 0,123,931을 찾을 수 있습니다