相关疑难解决方法(0)

如何在文本单元格中设置字体大小,以便字符串填充单元格的rect?

我有一个包含两个NSTextFieldCells 的视图.绘制这些单元格的大小是从视图的大小派生的,我希望每个单元格中的文本最大,以适合单元格的派生大小.这是我的,没有设置字体大小:

- (void)drawRect:(NSRect)dirtyRect {
    /*
     * Observant readers will notice that I update the whole view here. If
     * there is a perceived performance problem, then I'll switch to just
     * updating the dirty rect.
     */
    NSRect boundsRect = self.bounds;
    const CGFloat monthHeight = 0.25 * boundsRect.size.height;
    NSRect monthRect = NSMakeRect(boundsRect.origin.x,
                                  boundsRect.origin.y + boundsRect.size.height
                                  - monthHeight,
                                  boundsRect.size.width,
                                  monthHeight);
    [monthCell drawWithFrame: monthRect inView: self];

    NSRect dayRect = NSMakeRect(boundsRect.origin.x,
                                boundsRect.origin.y,
                                boundsRect.size.width,
                                boundsRect.size.height - monthHeight);
    [dayCell drawWithFrame: dayRect inView: self]; …
Run Code Online (Sandbox Code Playgroud)

cocoa text nstextfieldcell

5
推荐指数
1
解决办法
2835
查看次数

标签 统计

cocoa ×1

nstextfieldcell ×1

text ×1