getting a NSTextField to grow with the text in auto layout?

后端 未结 5 1458
有刺的猬
有刺的猬 2020-12-05 08:42

I\'m trying to get my NSTextField to have its height grow (much like in iChat or Adium) once the user types enough text to overflow the width of the control (as asked on thi

5条回答
  •  -上瘾入骨i
    2020-12-05 09:05

    And if you want to limit the size of the TextField (e.g.):

    if (intrinsicSize.height > 100) 
    {
        intrinsicSize = _lastIntrinsicSize;
    } 
    else
    {
        _lastIntrinsicSize = intrinsicSize;
        _hasLastIntrinsicSize = YES;
    }
    

    (Diff)

    One thing I’m having trouble with is getting the NSTextField embedded in an NSScrollView and having it work properly (especially within an NSStackView). Going to look at whether it wouldn’t be easier with NSTextView instead.

提交回复
热议问题