2014-10-13 5 views
2

나는 이것에 관해 여기에 게시 된 모든 답을 시도했다. 그리고 나는 여러 줄을 만들었지 만 지금부터는 약간의 부분부터 시작하는 텍스트가 필요하다. 제목 라벨을 어디에서 시작하길 원하는지 보여주는 스크린 샷을 참조하십시오. 나는 UIView의하지만 여전히 행운과 라벨을 교체 시도iOS 멀티 라인 제목 표시 줄

UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 44)]; 
[titleLabel setNumberOfLines:3]; 
[titleLabel setBackgroundColor:[UIColor darkGrayColor]]; 
[titleLabel setTextColor:[UIColor whiteColor]]; 
[titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:30.0]]; 
[titleLabel setText:@"LET'S GET YOU REGISTERED"]; 

self.navigationItem.titleView = titleLabel; 

-
http://i59.tinypic.com/23jl4jk.png

여기 내 코드입니다.
내 사용자 지정 탐색 컨트롤러 파일의 코드는 -

@interface UINavigationBar (myNave) 
- (CGSize)changeHeight:(CGSize)size; 
@end 

@implementation UINavigationBar (customNav) 
- (CGSize)sizeThatFits:(CGSize)size { 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    CGFloat screenHeight = screenRect.size.height * 0.15; 
    CGSize newSize = CGSizeMake(screenWidth,screenHeight); 
    return newSize; 
} 
@end 

도와주세요.

+0

비주얼 편집기에서 'titleLabel'을 움직이려 했습니까? – abiessu

+0

텍스트를 단순히 "등록"으로 변경하는 방법. 그건 한 줄에 들어 맞을거야. – Koen

+0

제목 라벨이 IB에 없습니다. 그것은 사용자 정의 탐색 막대를 사용하고 있기 때문에 그것은 프로그래밍 방식으로 추가되어야하고 그 문자열을 바꿀 수 없다. –

답변

3

텍스트 길이에 관계없이 numberOfLines를 설정해야합니다. 줄 수를 0으로 설정하면됩니다. 또한 크기 30 글꼴은 UINavigationItem (sizeToFit 제외)에 여러 줄 텍스트를 넣을 수 없습니다. UINavigationBar를 명확하게 설정하고 자신 만의 titleView를 만들면 크기가 30 인 경우 화면 상단에 맞출 수 있습니다.

그러나 이와 비슷한 기능을 사용하면 완벽하게 맞는 여러 줄 문자를 사용할 수 있습니다. 내비게이션 내부 :

UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(50, 0, self.navigationController.navigationBar.frame.size.width-100, self.navigationController.navigationBar.frame.size.height)]; 

UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, titleView.frame.size.width, titleView.frame.size.height)]; 
[titleLabel setTextAlignment:NSTextAlignmentCenter]; 
[titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12.0]]; 
[titleLabel setNumberOfLines:0]; 

NSString *titleString = @"This is a\n multiline string"; 
[titleLabel setText:titleString]; 

[titleView addSubview:titleLabel]; 

[self.navigationController.navigationItem setTitleView:titleView]; 
+0

약간의 변경을해야했지만 결국 효과가있었습니다. ans 주셔서 감사합니다 :) –