2012-03-05 71 views
1

當我運行這段代碼:的NSTextField setAlphaValue - 什麼也沒有發生

...

//draw the page 
    thisPage = [[Page alloc] initWithFrame:NSMakeRect(25.0, 25.0, pageSize.width, pageSize.height)]; 
    [masterPage addSubview:thisPage]; 

    //get the positioning for the page number 
    NSRect pageFrame = [thisPage frame]; 
    float xPos = pageFrame.size.width/2-pageFrame.size.width/4; 
    float yPos = pageFrame.size.height/2-pageFrame.size.height/4; 

    NSTextField* thisPageNum = [[NSTextField alloc] initWithFrame:NSMakeRect(xPos, yPos, 50.0, 50.0)]; 
    [thisPageNum setTextColor: [NSColor purpleColor]]; 
    [thisPageNum setAlphaValue:0.1]; 
    [thisPageNum setBordered: NO]; 
    [thisPageNum setEditable: NO]; 
    [thisPageNum setStringValue:[NSString stringWithFormat:@"%i", p+1]]; 
    [thisPageNum setFont:[NSFont fontWithName:@"Helvetica-Bold" size:36.0]]; 
    [thisPageNum setDrawsBackground:NO]; 
    [thisPage addSubview:thisPageNum]; 

當文本字段添加不存在的不透明度爲它在所有。這是爲什麼?

+1

什麼是目標SDK?它適用於我的10.7 SDK。在設置alpha值之前,嘗試添加'[thisPageNum setWantsLayer:YES]'。 – hamstergene 2012-03-05 17:35:36

回答

1

您正在將setDrawsBackground設置爲NO。這自然會使文本字段顯示爲透明。

刪除,應該有助於您獲得所需的結果。

相關問題