zoukankan      html  css  js  c++  java
  • NSTableView NSImage

    NSTableView主要代码
     
    // create a table view and a scroll view
    NSScrollView * tableContainer = [[NSScrollView alloc] initWithFrame:NSMakeRect(10, 10, 380, 200)];
    NSTableView * tableView = [[NSTableView alloc] initWithFrame:NSMakeRect(0, 0, 364, 200)];
    // create columns for our table
    NSTableColumn * column1 = [[NSTableColumn alloc] initWithIdentifier:@"Col1"];
    NSTableColumn * column2 = [[NSTableColumn alloc] initWithIdentifier:@"Col2"];
    [column1 setWidth:252];
    [column2 setWidth:198];
    // generally you want to add at least one column to the table view.
    [tableView addTableColumn:column1];
    [tableView addTableColumn:column2];
    [tableView setDelegate:self];
    [tableView setDataSource:self];
    [tableView reloadData];
    // embed the table view in the scroll view, and add the scroll view to our window.
    [tableContainer setDocumentView:tableView];
    [tableContainer setHasVerticalScroller:YES];
    [[self contentView] addSubview:tableContainer];
    [tableContainer release];
    [tableView release];
    [column1 release];
    [column2 release];
     
    摘抄自 stackoverflow
     
    另外,如果不想滑动 tableView,完全可以不用scrollView的,,,
    欢迎批评指正补充~
     
    NSImage

    刚开始用NSImage,从网上查找的方法是调用 imageNamed方法

    NSImage *myImage [NSImage imageNamed:@"imageName.png"] ;

    然后我加载一个绝对路径的图片怎么也显示不出来,在资源内的图片都可以显示出来。

    查了一些资料才知道:imageNamed加载一个图片的时候,先到到缓存中搜寻,看cache中是否存在,如果不存在则从资源中加载,用完了之后,其实这个图片会被缓存起来,且在缓存中一个图片对应一个唯一标识,默认为不带后缀的图片名,当然你可以主动的为某一个图片注册一个自己的标识也可以自己指定。

    NSImage *myImage [NSImage imageNamed:@"imageName.png"] ;
    [myImage setName:@"myImage"];

    这样之后你就可以通过[NSImage imageNamed:@"myImage"]来获取这个缓存中的图片了,如果你硬是不想缓存某个图片,那么你可以在用完了图片之后进行如下操作

    1 [myImage setName:nil];

    这样下次你加载图片的时候就会重新从资源中加载了。

    imageNamed方法是不能通过路径进行加载图片的,如果要通过路径加载图片可以通过下面两个方法加载,一个是URL一个是FilePath
    NSImage *image [[NSImage alloc]initWithContentsOfURL:(NSURL *)];
    NSImage *image [[NSImage alloc]initWithContentsOfFile:(NSString *)];

    用完记得 [image release];

    NSImageView上设置NSButton

    NSImageView *topBar = [[NSImageView alloc] initWithFrame: NSMakeRect(20074280058)]; 

            [topBar setImage: [NSImage imageNamed: @"TitleBar.png"]]; 
            [self.window.contentView addSubview: topBar]; 
              
            NSButton *undoBtn = [[NSButton alloc] initWithFrame: NSMakeRect(10303026)]; 
            [undoBtn setButtonType: NSMomentaryLightButton]; 
            [undoBtn setImage: [NSImage imageNamed: @"Undo [Normal].png"]]; 
            [topBar addSubview: undoBtn]; 
  • 相关阅读:
    cookie,请求报文,
    ser,ver
    关于 通知的 死循环,
    这读取的好蛋疼,为什么一写 一读就有问题了,不一致了,
    缓存小姐 挡拆,网络请求 不同步 惹的祸,
    viewdidload ,viewwillappear,
    提示输入 用户名 ,密码,--》转
    前端面试
    npm与cnpm
    vue与node和npm关系
  • 原文地址:https://www.cnblogs.com/conanwin/p/4666955.html
Copyright © 2011-2022 走看看