NSCollectionView 实现选中效果
来源:互联网 发布:阿里手机小号软件 编辑:程序博客网 时间:2024/04/29 09:30
(一)实现选中,并对View添加效果:
1:首先需要设置NSCollectionView允许选中。
可以在IB里面选中CollectionView 后勾选selectable,或者直接代码设置可以勾选
[_collectionView setSelectable:YES];
2:对NSCollectionViewItem的View进行重画,添加一个是否选中的属性
@interface AlexNSCollectionViewItemView :NSView
{
BOOL _isSelected;
}
@property (nonatomic,assign)BOOL isSelected;
@implementation AlexNSCollectionViewItemView
@synthesize isSelected =_isSelected;
- (id)initWithFrame:(NSRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
NSRect imageRect =NSMakeRect(5,5,self.frame.size.width -10,self.frame.size.height -10);
NSBezierPath* imageRoundedRectanglePath = [NSBezierPathbezierPathWithRoundedRect:imageRectxRadius: 4 yRadius: 4];
NSColor* fillColor =nil;
NSColor* strokeColor =nil;
//默认是未选中的
if (_isSelected) {
fillColor = [NSColorcolorWithCalibratedRed:0.851green:0.851blue:0.851alpha:1];
strokeColor = [NSColorcolorWithCalibratedRed:0.408 green:0.592 blue:0.855 alpha:1];
}else{
fillColor = [NSColorclearColor];
strokeColor = [NSColorcolorWithCalibratedRed:0.749 green:0.749 blue:0.749 alpha:1];
}
[fillColorsetFill];
[imageRoundedRectanglePathfill];
[strokeColorsetStroke];
[superdrawRect:dirtyRect];
}
- (void)setIsSelected:(BOOL)isSelected
{
_isSelected = isSelected;
[selfsetNeedsDisplay:YES];
}
3:重写NSCollectionViewItem的selected方法
@interface ALExNSCollectionVIewItem :NSCollectionViewItem
@end
@implementation ALExNSCollectionVIewItem
- (void)setSelected:(BOOL)selected
{
[(AlexNSCollectionViewItemView *)[selfview]setIsSelected:selected];
[supersetSelected:selected];
}
4:然后将重写的类在IB中设置到相应的控件的Class上。允许程序,点击鼠标选中,就能看到选中效果了。Good Luck!
- NSCollectionView 实现选中效果
- RadioButton选中效果实现
- css实现图片选中效果
- CCMenuItemToggle实现选中的效果
- CCScale9Sprite实现技能选中效果
- jQuery实现li选中效果
- NSCollectionView 基础
- mac NSCollectionView
- CSS实现图片选中加边框效果
- Android gallery实现选中放大的效果
- Android gallery实现选中放大的效果
- Android gallery实现选中放大的效果
- VC 实现菜单项选中效果
- js实现span文本选中效果
- Android Gallery实现选中放大的效果
- 简单实现ListView选中后的效果
- [Android] Gallery选中变大效果的实现
- JQ实现效果:焦点选中样式
- 为什么我们要学/用Perl?
- 青蛙的约会
- Codeforces Round #238 (Div. 2)
- 该改变学习方向了
- 第3天打卡---enhance grep/kill hange process
- NSCollectionView 实现选中效果
- 学习英语音标,坚持
- 深入理解C语言-09 编译器介绍
- Activity、Window和View三者间的关系【Android】
- 题目1199:找位置
- Android开发:shape和selector和layer-list的(详细说明)
- 使用Pushlet将消息从服务器端推送到客户端
- sealed关键字——密封类
- JSP Cookie使用方法详解