2011-11-25 2 views
0

UILabel의 줄 간격에 MTLabel 클래스를 사용해야합니다.MTLabel을 사용한 장치 회전 문제

(대해 참조 샘플 코드 : https://github.com/Tuszy/MTLabel)

그러나 몇 가지 문제가 존재한다.

저는 iPad 앱을 만들고 있습니다. 이 앱은 가로 또는 세로로 회전 할 수 있습니다.

IB없이 UILabel 및 MTLable 개체를 볼 수 있습니다.

장치의 방향이 변경 될 때마다 텍스트의 너비도 변경됩니다.

이 결과는 내가 원하는 것이 아닙니다.

내 코드 :

#import "MTLabel.h" 

.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    MTLabel *TitleFont = [[MTLabel alloc] initWithFrame:CGRectMake(255, 60, 270, 60)]; 

    [TitleFont setFont:[UIFont fontWithName:@"Arial" size:30.0]]; 

    TitleFont.backgroundColor = [UIColor greenColor]; 
    TitleFont.text = @"Happy! - 1"; 
    TitleFont.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; 

    TitleFont.autoresizingMask= UIViewAutoresizingFlexibleWidth; 

    [self.view addSubview:TitleFont]; 

    //---------------------- 

    UILabel *TitleFont2 = [[UILabel alloc] initWithFrame:CGRectMake(255, 120, 270, 60)]; 

    [TitleFont2 setFont:[UIFont fontWithName:@"Arial" size:30.0]]; 

    TitleFont2.backgroundColor = [UIColor orangeColor]; 
    TitleFont2.text = @"Happy! - 2"; 
    TitleFont2.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; 

    TitleFont2.autoresizingMask= UIViewAutoresizingFlexibleWidth; 

    [self.view addSubview:TitleFont2]; 



} 

결과 : 1) 초상화 이미지 :

enter image description here

2) 풍경 이미지 : enter image description here

내가 UILabel의 클래스를 사용하는 경우, 아무 문제! 하지만 UILabel의 줄 간격에 MTLabel 클래스가 필요합니다.

제발 .. 고맙습니다.

[TitleFont setContentMode:UIViewContentModeRedraw]; 

답변

1

이 시도. 아마도 didRotateFromOrientation에있을거야.

0

당신은 새 크기에서 제대로 자신을 다시 그리 setNeedsDisplay와 MTLabel을 걷어해야합니다 :

0
[TitleFont setNeedsDisplay] 

시도해보십시오. 을 사용 중지해야합니다. setAutoresizesSubviews:<NO>