objective c - Not editable NSTextfiled, to make it auto resize when string is too long, like english word to French -


as question being posted, in textfield, when open app in english, works well, when switching french, know french word quite long , in case, words showing in textfield cut off.

i tried customised way textfield on stack overflow, works editable textfield, when made none-editable, behaviour wired.

it's when word long, make textfield longer, meaning increase width, not height. i'm expecting keeping width fix while changing height when word long.

intrinsicsize = [super intrinsiccontentsize]; nstextview *textview = (nstextview *)fieldeditor;          nsrect usedrect = [textview.textcontainer.layoutmanager usedrectfortextcontainer:textview.textcontainer]; 

kind of 2 main func used, when it's editable, went , height changes while width fix, when it's none editable, width changes.

any advice?

in nstextfield subclass override following methods. make sure nstextfield set wrap in ib. add constraints it.

 -(nssize)intrinsiccontentsize {     // if wrap not enabled return original size     if ( ![self.cell wraps] ) {     return [super intrinsiccontentsize];      nsrect frame = [self frame];     cgfloat width = frame.size.width;     // allow grow in height , not width     frame.size.height = cgfloat_max;     cgfloat height = [self.cell cellsizeforbounds: frame].height;     // return calculated height     return nsmakesize(width, height); }  // listen text change notification , invalidate default size - (void)textdidchange:(nsnotification *)notification {     [super textdidchange:notification];     [self invalidateintrinsiccontentsize]; } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -