2012-12-19 5 views
6

레이어 내 텍스트의 글꼴 속성을 수정하려고하지만 발생하지 않습니다. 누구든지 도와 줄 수 있습니까? 코드를 검색 :CATextLayer에서 글꼴 크기 및 유형이 적용되지 않습니다.

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 

if (self) 
{ 

    // All HypnosisViews start with a clear background color 

    [self setBackgroundColor:[UIColor clearColor]]; 
    [self setCircleColor:[UIColor lightGrayColor]]; 


    // Create the new layer object 
    boxLayer = [[CATextLayer alloc] init]; 

    // Give it a size 
    [boxLayer setBounds:CGRectMake(0.0, 0.0, 300.0, 85.0)]; 

    // Give it a location 
    [boxLayer setPosition:CGPointMake(160.0, 350.0)]; 

    // Make half-transparent red the background color for the layer 
    UIColor *reddish = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.75]; 

    // Get CGColor object with the same color values 
    CGColorRef cgReddish = [reddish CGColor]; 
    [boxLayer setBackgroundColor:cgReddish]; 

    // Make it a sublayer on the view's layer 
    [[self layer] addSublayer:boxLayer]; 

    NSString *text2 = @"You are me."; 
    UIFont *font2 = [UIFont fontWithName:@"Times New Roman" size:10.0]; 
    [text2 sizeWithFont:font2]; 


    [boxLayer setString:text2]; 

} 
return self; 
} 

답변

7

가 CATextLayer의 글꼴/글꼴 크기를 변경하려면 "글꼴"과 레이어의 "fontSize는"속성에 값을 할당해야합니다.

또는 NSAttributedString을 사용해야하는 경우 해당 문자열 개체의 값이 사용됩니다.

"sizeWithFont"호출은 사용자가 지정한 글꼴의 너비와 높이로 CSSize를 계산하고 반환하는 NSString 추가 기능입니다. 코드에서 반환 된 CGSize를 사용하지 않으므로 절대적으로 아무것도하지 않습니다. 의 참조

+0

이것은 환상적입니다. 감사. 그것은 효과가 있었다. – Armand

+0

완벽 함 - 찾고있는 것이라면 올바른 답으로 표시하여 다른 사람에게 표시되도록합니다. 해결되었습니다! –

+0

물론 어떻게 할 것인가? 나는이 사이트에서 새로운 사람이다. CATextLayer에 대해서 : 레이어 코너를 반올림 할 방법이 있습니까? 그리고 레이어 안의 텍스트에 대해 어떻게 선을 끊으시겠습니까? – Armand