首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以更改NSTextView的标题高度?

是否可以更改NSTextView的标题高度?
EN

Stack Overflow用户
提问于 2012-01-28 02:29:13
回答 1查看 508关注 0票数 1

我正在保存一个NSTextview格式的文件,并在标题中放置一个徽标。我覆盖了pageHeader,出现了徽标,但它被裁剪了。

是否可以更改NSTextView的标题高度

谢谢!

部分代码:

代码语言:javascript
复制
-(IBAction)impLaudo:(id)sender 
{
    NSPrintInfo *printInfo;
    NSPrintInfo *sharedInfo;
    NSPrintOperation *printOp;
    NSMutableDictionary *printInfoDict;
    NSMutableDictionary *sharedDict;

    sharedInfo = [NSPrintInfo sharedPrintInfo];
    sharedDict = [sharedInfo dictionary];
    printInfoDict = [NSMutableDictionary dictionaryWithDictionary:sharedDict];

    [printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
    [printInfoDict setObject:[[dirLaudos stringByAppendingString:[estudo stringValue]] stringByAppendingString:@".pdf"] forKey:NSPrintSavePath];

    printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
    [printInfo setHorizontalPagination: NSClipPagination];
    [printInfo setVerticalPagination: NSAutoPagination];
    [printInfo setVerticallyCentered:NO];
    [[printInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter];

    printOp = [NSPrintOperation printOperationWithView:textView printInfo:printInfo];
    [printOp setShowsPrintPanel:NO];
    [printOp runOperation];    
}


@implementation MyTextView 

- (NSAttributedString *)pageHeader
{
    // Adicionando cabeçalho
    NSAttributedString *theHeader = nil;

    NSImage * pic = [[NSImage alloc] initWithContentsOfFile:[dirLayout stringByAppendingString:@"cabecalho.jpg"]];
    NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic];
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    [attachment setAttachmentCell: attachmentCell ];
    theHeader = [NSAttributedString  attributedStringWithAttachment: attachment];
    return theHeader;
}

@end    
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-28 06:11:14

您应该覆盖允许您在打印时在页面上绘制额外标记的-drawPageBorderWithSize:,而不是覆盖-pageHeader

Size参数是一个包含当前逻辑页大小的NSSize结构。您需要做的就是在正确的位置绘制您的徽标:

代码语言:javascript
复制
- (void)drawPageBorderWithSize:(NSSize)pageSize
{
    [super drawPageBorderWithSize:pageSize];
    //draw your logo
    NSPoint offset = NSMakePoint(100.0, 100.0);
    NSImage* logo = [NSImage imageNamed:@"logo"];
    NSSize logoSize = [logo size];
    NSPoint imageOrigin = NSMakePoint(offset.x, pageSize.height - (offset.y + logoSize.height));
    [self lockFocus];
    [logo drawInRect:NSMakeRect(imageOrigin.x, imageOrigin.y, logoSize.width, logoSize.height)
            fromRect:NSZeroRect 
           operation:NSCompositeSourceOver
            fraction:1.0 
      respectFlipped:YES 
               hints:nil];
    [self unlockFocus];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9038240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档