2012-09-16 5 views
1

루프를 만들어 일부 UILabels를 만들고 CALayer에 .layers를 추가합니다. 나중에 UILmage에 대해 오프 스크린으로 렌더링합니다 (BTW : I '주에 다시 전달하기 전에 다른 큐에이 렌더링을 수행 M)UILabel.layer가 for 루프 범위 밖에서 유지되지 않습니다.

이 같은 루프에 그것을 할 경우.

for (i=0; i<offlineModel.modelArray.count; i++) { 

    UILabel *newLabel = [[UILabel alloc] init]; 
    [newLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:9.0]]; 
    [newLabel setTextColor:[UIColor colorWithRed:76/255.0 green:76/255.0 blue:78/255.0 alpha:1.0]]; 
    [newLabel setShadowColor:[UIColor whiteColor]]; 
    [newLabel setShadowOffset:CGSizeMake(1, 1)]; 
    [newLabel setBackgroundColor:[UIColor greenColor]]; 
    [newLabel setTextAlignment:UITextAlignmentCenter]; 
    [newLabel setNumberOfLines:0]; 

    [newLabel setText:[(LVBarGraphModelPair *)[offlineModel.modelArray objectAtIndex:i] xValue]]; 
    [newLabel setBounds:CGRectMake(0, 0, barWidth+barSpacing, 3*8.0)]; 
    [newLabel setAdjustsFontSizeToFitWidth:NO]; 
    [newLabel sizeToFit]; 

    CGPoint center = CGPointMake((((offlineModel.modelArray.count-i-1)*barSpacing)+placeholderBarContainerLayerRect.origin.x+(.5*barWidth)), placeholderBarContainerLayerRect.size.height); 

    [newLabel setCenter:center]; 
    [newLabel setFrame:CGRectMake(lroundf(newLabel.frame.origin.x), lroundf(placeholderBarContainerLayerRect.origin.y + placeholderBarContainerLayerRect.size.height+LVBARGRAPH_BAR_ANIMATION_XAXIS_LABELS_OFFSET_X), newLabel.frame.size.width, newLabel.frame.size.height)]; 

    [layer addSublayer:newLabel.layer]; 
} 

내가 흑인의 구형을 얻을 label를 : 그래서 Black Rects instead of labels 문제를 해결하려면 루프 대신 동일한 코드를 사용하여 6 대신 하나를 만듭니다.

UILabel *newLabel = [[UILabel alloc] init]; 
    [newLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:9.0]]; 
    [newLabel setTextColor:[UIColor colorWithRed:76/255.0 green:76/255.0 blue:78/255.0 alpha:1.0]]; 
    [newLabel setShadowColor:[UIColor whiteColor]]; 
    [newLabel setShadowOffset:CGSizeMake(1, 1)]; 
    [newLabel setBackgroundColor:[UIColor greenColor]]; 
    [newLabel setTextAlignment:UITextAlignmentCenter]; 
    [newLabel setNumberOfLines:0]; 

    [newLabel setText:[(LVBarGraphModelPair *)[offlineModel.modelArray objectAtIndex:i] xValue]]; 
    [newLabel setBounds:CGRectMake(0, 0, barWidth+barSpacing, 3*8.0)]; 
    [newLabel setAdjustsFontSizeToFitWidth:NO]; 
    [newLabel sizeToFit]; 

    CGPoint center = CGPointMake((((offlineModel.modelArray.count-i-1)*barSpacing)+placeholderBarContainerLayerRect.origin.x+(.5*barWidth)), placeholderBarContainerLayerRect.size.height); 

    [newLabel setCenter:center]; 
    [newLabel setFrame:CGRectMake(lroundf(newLabel.frame.origin.x), lroundf(placeholderBarContainerLayerRect.origin.y + placeholderBarContainerLayerRect.size.height+LVBARGRAPH_BAR_ANIMATION_XAXIS_LABELS_OFFSET_X), newLabel.frame.size.width, newLabel.frame.size.height)]; 

    [layer addSublayer:newLabel.layer]; 

Without loop it shows up!

그리고 그것은 거기! 무슨 일 이니?

루프가 필요하므로 변수가 다양 할 수 있습니다.

답변

0

UILabel을 생성하고 레이어를 사용하는 대신 CATextLayer을 사용해야합니다.

+0

텍스트 그림자를 지원합니까? –

+0

이것은'CALayer'의 서브 클래스입니다. 그렇습니다. ('CALayer'의'shadowXXX' 속성을보세요). – AliSoftware

+0

잠깐, TEXT 그림자가 생길까요? –

관련 문제