2013-07-02 77 views
0

我使用下面的函數轉換文本框標記,反之亦然轉換的NSTextField

-(void)convertLabelToTextField : (NSTextField *)Inlabel 
{ 
    [Inlabel setBezeled:YES]; 
    [Inlabel setDrawsBackground:YES]; 
    [Inlabel setEditable:YES]; 
    [Inlabel setSelectable:YES]; 
} 

-(void)convertTextFieldToLable : (NSTextField *)textField 
{ 

    [textField setDrawsBackground:NO]; 
    [textField setEditable:NO]; 
    [textField setSelectable:NO]; 
    [textField setBezeled:NO]; 

} 

但我的UI是不是一致的標籤。

  • 初始標籤

enter image description here

  • 標籤到文本字段

enter image description here

  • Textf ield到標籤(選擇文本後)

enter image description here

  • 標籤到文本框

enter image description here

enter image description here

誰能請幫助我。

回答

3

罪魁禍首標籤的默認HIGHT。

標籤默認高度

enter image description here

的NSTextField默認高度

hight of textfield

下面

與高度22

NSTextField *textField; 

textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 100, 22)]; 
[textField setStringValue:@"My Label"]; 
[textField setBezeled:NO]; 
[textField setDrawsBackground:NO]; 
[textField setEditable:NO]; 
[textField setSelectable:NO]; 
0

嘗試設置調整大小掩蓋

[textField setAutoresizingMask: NSViewMinXMargin | NSViewWidthSizable | NSViewMaxXMargin | NSViewMinYMargin | NSViewHeightSizable | NSViewMaxYMargin]; 

See this answer

+0

還是同樣的問題對標籤代碼:( –