Question

I am using following functions for converting textfield to label and vice versa

-(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];

}  

But my UI is not consistent.

  • Initial Label

enter image description here

  • Label to textfield

enter image description here

  • Textfield to Label (after selecting text)

enter image description here

  • Label to textfield

enter image description here

enter image description here

Can anyone please help me out.

Était-ce utile?

La solution

Culprit was default hight of label.

label Default height

enter image description here

NSTextField Default height

hight of textfield

below is code for Label with height 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];

Autres conseils

Try setting Resizing mask

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

See this answer

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top