首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在NSTableviewcell中制作圆形图像

如何在NSTableviewcell中制作圆形图像
EN

Stack Overflow用户
提问于 2014-07-28 12:17:00
回答 1查看 148关注 0票数 0

我正在尝试创建一个mac应用程序,在我的表视图中,我有一个标签和图像视图

代码语言:javascript
复制
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    NSString *cellId = @"Feature";
    NSTableCellView *cellView =[tableView makeViewWithIdentifier:cellId owner:self];

    if([tableColumn.identifier isEqualToString:@"FeaturesColumn"]){
        if([cellId isEqualToString: @"Feature"]){
            CALayer *imageLayer = cellView.imageView.layer;
            [imageLayer setCornerRadius:30.0f];
            [imageLayer setBorderWidth:1];
            [imageLayer setMasksToBounds:YES];
            [cellView.imageView setLayer:imageLayer];
            [cellView.textField setStringValue:[_features objectAtIndex:row]];
            return cellView;
        }

    }
    return cellView;
}

但每当我运行模拟时,我得到的都是矩形图像

EN

回答 1

Stack Overflow用户

发布于 2014-07-28 12:46:41

尝试以下代码:

代码语言:javascript
复制
// Get your image somehow
    UIImage *image = [UIImage imageNamed:@"image.jpg"];

    // Begin a new image that will be the new image with the rounded corners
    // (here with the size of an UIImageView)
    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);

    // Add a clip before drawing anything, in the shape of an rounded rect
    [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
    cornerRadius:10.0] addClip];
    // Draw your image
    [image drawInRect:imageView.bounds];

    // Get the image, here setting the UIImageView image
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();

    // Lets forget about that we were drawing
    UIGraphicsEndImageContext();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24988355

复制
相关文章

相似问题

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