我想制作一个标签,根据它将显示的字符串值的大小来改变其大小。目前我这样做:
[tfScroll setStringValue:strScoller];
[tfScroll sizeToFit];
然而这不起作用。我错过了什么?
答案 0 :(得分:4)
如果你的tfScroll是NSTextField:
CGRect frame = tfScroll.frame;
frame.size.width = tfScroll.attributedStringValue.size.width+somepoints;//(somepoints=8)
tfScroll.frame = frame;
我没有找到NSTextfield.contentSize。
答案 1 :(得分:1)
如果您尝试调整字段高度,可能会有效:
CGRect frame = tfScroll.frame;
frame.size.height = tfScroll.contentSize.height;
tfScroll.frame = frame;