如何使NSTextField真的单线?
我以编程方式创建了一个文本字段.按下返回键时,将选择所有文本.但我仍然可以粘贴多行文字.当我向右箭头或向下箭头按下时,它会滚动到下一行.
如果我使用IB并设置"使用单行模式",则没有这些问题,但我找不到以编程方式设置它的正确方法.
我想制作一个菜单栏,它在滚动时固定在页面顶部.类似Facebook的顶级菜单.
此外,我想要一个div保持菜单左侧的徽标浮动,以及菜单栏右侧的导航浮动.
db.define_table('person',Field('name'),format ='%(name)s')
这种格式在这里做什么?
我有两个窗口:窗口A是从NIB加载的; 和Window B以编程方式创建.
两个窗口都有一个NStextView:窗口A中textview的attributionString绑定到使用IBtext的模型的属性; 而Window B中textview的attributionString绑定到模型的属性使用方法.text-[NSObject bind:toObject:withKeyPath:options:]
[textview bind:@"attributedString"
toObject:obj
withKeyPath:@"text"
options:nil];
Run Code Online (Sandbox Code Playgroud)
这是奇怪的事情:Window B中的textview确实绑定了obj.text,但textview中的更改永远不会更新obj.text.但是,如果我在窗口A的文本视图中进行了更改,则obj.text窗口B中的文本视图也会相应更新.
所以我在想,这个-[NSObject bind:toObject:withKeyPath:options:]方法只适用于单向绑定.我在Cocoa文件中找不到明确的解释.有没有人遇到过这个问题?如何在代码中实现双向绑定?
我通过覆盖更改插入点大小-(void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag,但它不处理第一次闪烁(当您移动插入点时,它会恢复正常)
我设法通过重写私有方法来处理第一次闪烁- (void)_drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor.
但这对我来说不是一个解决方案,因为重写私有方法将导致App Store下降.我希望该应用程序在App Store中.我看到像iAWriter和Writeroom这样的应用程序有一个自定义插入点,它们在App Store中.
有谁知道他们是如何设法做到这一点,或者更好的方式而不是覆盖私有方法?
谢谢.
- (void)_drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor
{
aRect.size.width = 3.0;
[aColor set];
[NSBezierPath fillRect:aRect];
}
- (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag
{
if(flag) {
aRect.size.width = 3.0;
[aColor set];
[NSBezierPath fillRect:aRect];
}
else {
[self setNeedsDisplayInRect:[self visibleRect] avoidAdditionalLayout:NO];
}
}
Run Code Online (Sandbox Code Playgroud) fun curry f x y = f (x, y);
fun uncurry f (x, y) = f x y;
fun compose (f, g) x = f (g x);
Run Code Online (Sandbox Code Playgroud)
我理解compose功能,但不太了解ML中的curry和uncurry.谁能解释一下这些?
另外,以下两行是什么意思?
(1) compose (compose, uncurry compose)
(2) compose (uncurry compose, compose)
Run Code Online (Sandbox Code Playgroud) 我有一个_keywords字符串数组的字段.我想获取哪些文件_keywords是查询数组的超集.
例如:
db.article.insert({'_keywords': ['foo', 'foo1', 'foo2']})
Run Code Online (Sandbox Code Playgroud)
当我查询['foo','foo1','foo2']的子集时,我想要检索此记录,例如:['foo'],['foo1','foo2']
编辑:类似于:
db.article.find({'_keywords': {$contains: array}})
Run Code Online (Sandbox Code Playgroud) 我有一个NSOutlineView,如果它是可扩展的,点击一行将展开/折叠该项目.
if ([self.outlineView isItemExpanded:item]) {
NSLog("Will collapse item : %@", item);
[[self.outlineView animator] collapseItem:item];
}
else {
[[self.outlineView animator] expandItem:item];
}
Run Code Online (Sandbox Code Playgroud)
扩展项目按预期工作,但折叠项目不起作用.我在执行collapseItem:之前确实得到了日志,并且该项是正确的.委托方法- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item也没有被调用.
这个问题已经持续了好几个小时.有什么想法导致这个?
我使用以下方法从文件系统获取解压缩的uiimage.但是,当我打开颜色混合图层时,即使UIImageView设置为不透明,UIImageView也会显示为红色.
文件系统上的图像没有alpha通道.我尝试设置CGContextSetAlpha(bitmapContext,1),但仍然有混合层.
任何人都知道如何在使用CGContextDrawImage时删除alpha通道?
- (UIImage *)decompressedImage
{
CGImageRef imageRef = self.CGImage;
CGRect rect = CGRectMake(0.f, 0.f, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
rect.size.width,
rect.size.height,
CGImageGetBitsPerComponent(imageRef),
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little
);
// kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little are the bit flags required
// so that the main thread doesn't have any conversions to do.
CGContextDrawImage(bitmapContext, rect, imageRef);
CGImageRef decompressedImageRef = CGBitmapContextCreateImage(bitmapContext);
UIImage* decompressedImage = [UIImage imageWithCGImage:decompressedImageRef
scale:[[UIScreen mainScreen] scale]
orientation:UIImageOrientationUp];
CGImageRelease(decompressedImageRef);
CGContextRelease(bitmapContext);
return decompressedImage;
}
Run Code Online (Sandbox Code Playgroud)