[Cocoa]_[初级]_[NSTableView添加背景图片]
2015-02-28 11:06
323 查看
头文件 MyTableView.h
源文件 MyTableView.m
#import <Cocoa/Cocoa.h> @interface MyTableView : NSTableView { NSImage* backgroundImage; } - (void)setBackgroundImage:(NSImage*)image; - (void)clearBackgroundImage; @end
源文件 MyTableView.m
#import "MyTableView.h" @implementation MyTableView -(void)awakeFromNib { // this is important for background images in outline views - // use it if you don't want the scroller to cause the background to redraw // Without it, if the user scrolls the background tries to draw at the same time (we don't want that). // [[self enclosingScrollView] setDrawsBackground: NO]; } -(void)drawBackgroundImage { if (backgroundImage != nil) { NSRect visRect = [[self enclosingScrollView] documentVisibleRect]; [backgroundImage setFlipped:YES]; [backgroundImage drawInRect:NSMakeRect(visRect.origin.x, visRect.origin.y, [self frame].size.width, [self frame].size.height) fromRect:NSMakeRect(0,0,[backgroundImage size].width, [backgroundImage size].height) operation:NSCompositeCopy fraction:1.0]; [backgroundImage setFlipped:NO]; } } - (void)drawBackgroundInClipRect:(NSRect)clipRect { // drawing our background image in this method does not work all by itself, // because the clipping area has been set and not ALL the background // will update properly. You also need to implement "drawRect" as well // [super drawBackgroundInClipRect:clipRect]; [self drawBackgroundImage]; } - (void)drawRect:(NSRect)drawRect { [self drawBackgroundImage]; [super drawRect: drawRect]; } // method used to set and turn on the background image, forces an update - (void)setBackgroundImage:(NSImage*)image { backgroundImage = [image retain]; [self setNeedsDisplay: YES]; } // method used to remove or clear the background image, forces an update - (void)clearBackgroundImage { if (backgroundImage != nil) { [backgroundImage release]; backgroundImage = nil; } [self setNeedsDisplay: YES]; } @end
相关文章推荐
- MFC中 给基于CFormView的单文档添加背景图片
- [Cocoa]_[初级]_[NSTableView--数据操作和表格操作要注意的问题]
- 请问,如何在NSTableView 的单元格中添加图片呢?
- [Cocoa]_[初级]_[在一张图片上添加图片水印和文字水印]
- CardView 添加背景图片、改变颜色、水波纹效果的方法
- 在WebView 中添加一个背景图片
- 给TableView添加背景图片的方法!!!
- UIView UITableView 背景图片添加
- [Cocoa]_[NSTableView]_[添加复选框]
- IOS UITapGestureRecognizer 遇到父view添加UIImageView的背景图片,子subview的tap事件不起作用了
- [Cocoa]_[初级]_[NSTableView之自定义NSImageButtonCell]
- [Cocoa]_[初级]_[自定义NSTableHeaderView]
- MFC中添加一张图片作为对话框(或CFormView)的背景
- UIScrollView-添加自适应的背景图片
- 如何给View添加背景图片
- 资源管理器添加漂亮的图片当背景
- 关于为对话框添加背景图片LoadBitmap的问题
- DataGridView 添加背景图片
- javaz中背景图片的添加
- 添加和切换对话框背景图片