Objective c 如何在NSTableviewcell中制作圆形图像
我正在尝试制作一个mac应用程序,在我的tableview中有一个标签和imageviewObjective c 如何在NSTableviewcell中制作圆形图像,objective-c,macos,cocoa,nstableview,Objective C,Macos,Cocoa,Nstableview,我正在尝试制作一个mac应用程序,在我的tableview中有一个标签和imageview -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ NSString *cellId = @"Feature"; NSTableCellView *cellView =[tableView makeViewWithI
-(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;
}
但每当我运行模拟时,得到的都是矩形图像请尝试以下代码:
// 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();
将图像遮罩与一些圆形遮罩图像一起使用,以圆形显示图像。示例:这是针对iphone的,不是吗?掩蔽是以形状和设计显示图像的最简单方法。我是否需要为这些类导入uikit或其他内容?如果uikit已经在.pch文件中,则不需要导入,否则不需要导入。是的,您必须这样做。答案是针对iOS,而不是针对OS X。这些功能在中不存在热可可