cocoa – 获取NSTextField内容以进行扩展

前端之家收集整理的这篇文章主要介绍了cocoa – 获取NSTextField内容以进行扩展前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何才能使文本比例符合我给出的界限?

解决方法

我过去做过类似的事. @H_301_6@-(void)calcFontSizeToFitRect:(NSRect)r { float targetWidth = r.size.width - xMargin; float targetHeight = r.size.height - yMargin; // the strategy is to start with a small font size and go larger until I'm larger than one of the target sizes int i; for (i=minFontSize; i<maxFontSize; i++) { NSDictionary* attrs = [[NSDictionary alloc] initWithObjectsAndKeys:[NSFont fontWithName:currentFontName size:i],NSFontAttributeName,nil]; NSSize strSize = [string sizeWithAttributes:attrs]; [attrs release]; if (strSize.width > targetWidth || strSize.height > targetHeight) break; } [self setCurrentFontSize:(i-1)]; }

字符串变量是您想要调整大小的文本. xMargin和yMargin变量用于您想要的间距. minFontSize和maxFontSize变量限制了您想要的小或大.

原文链接:https://www.f2er.com/css/214117.html

猜你在找的CSS相关文章