当我使用drawInRect:withAttributes:并传入段落样式NSTextAlignmentCenter和非零值时NSKernAttributeName,字符串不会正确居中.我做错了什么或这是预期的行为?有解决方法吗?
截图:

您可以清楚地看到顶部文本未正确居中.
我的演示代码:
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIFont *font = [UIFont systemFontOfSize:15.0];
[self drawString:@"88" inRect:rect font:font textColor:[UIColor blackColor]];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextAddRect(context, rect);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
- (void)drawString:(NSString *)text
inRect:(CGRect)contextRect
font:(UIFont *)font
textColor:(UIColor *)textColor
{
CGFloat fontHeight = font.lineHeight;
CGFloat yOffset = floorf((contextRect.size.height - fontHeight) / 2.0) + contextRect.origin.y;
CGRect textRect = CGRectMake(contextRect.origin.x, yOffset, contextRect.size.width, fontHeight);
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByClipping;
paragraphStyle.alignment = NSTextAlignmentCenter;
[text …Run Code Online (Sandbox Code Playgroud) resultLabel是一个UILabel.那么为什么呢
resultLabel.Text= @"";
Run Code Online (Sandbox Code Playgroud)
不给出错误?它应该是resultLabel.text.
感谢您的任何见解.
WKWebView在 iOS 11 和 12 上长按 a 中的图像或链接会启动拖放会话(用户可以拖动图像或链接)。我怎样才能禁用它?
在这种情况下,无论是locales和aliases共享相同的结构,所以我重复他们以同样的方式只改变其名称.
if yml_site['locales'].present?
yml_site['locales'].each_value do |yml_locale|
site = Site.find_or_create_by_domain(
locale: yml_locale['locale'],
domain: yml_locale['domain'],
title: yml_locale['title'],
parent: yml_site['domain'],
end
end
if yml_site['aliases'].present?
yml_site['aliases'].each_value do |yml_alias|
site = Site.find_or_create_by_domain(
locale: yml_alias['locale'],
domain: yml_alias['domain'],
title: yml_alias['title'],
parent: yml_alias['domain'],
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想用简单的东西来简化这段代码,[yml_site['locales'],yml_site['aliases']].each.each_value但是很明显它不起作用.任何想法我如何迭代yml_site['locales']和yml_site['aliases']同一个查询?
我想将 NSTask(NSTask、launchpath 和 args)传递给一个函数,但我确实需要一些语义方面的帮助:
AppleDelegate.h 文件:
- (void)doTask:(NSTask*)theTask :(NSArray*)arguments :(NSString*)launchPath;
Run Code Online (Sandbox Code Playgroud)
AppleDelegate.m 文件:
- (void)doTask:(NSTask*)theTask :(NSArray*)arguments :(NSString*)launchPath
{
self.currentTask = theTask;
// do currentTask alloc, set the launcpath and the args, pipe and more
}
Run Code Online (Sandbox Code Playgroud)
这是调用“doTask”的代码:
NSTask* runMyTask;
NSString *command = @"/usr/bin/hdiutil";
NSArray* taskArgs = [NSArray arrayWithObjects:@"info", @"/", nil];
// Here the error:
[self doTask:runMyTask, taskArgs, command]; // ARC Semantic issue no visible interface for AppleDelegate declares the selector 'doTask'..
Run Code Online (Sandbox Code Playgroud)
选择器显示为未声明,但我以为我确实声明了它......是否可以做这样的事情,错误在哪里?
假设我有一个 TypeScript 1.6 文件,其中包含这一行,其中包含 JSX (TSX):
var a = (<div></div>);
Run Code Online (Sandbox Code Playgroud)
当我使用 TypeScript 1.6(通过 ntypescript npm 包安装)在命令行上编译它时:
ntsc --jsx react test.tsx
Run Code Online (Sandbox Code Playgroud)
它产生预期的输出:
more test.js
var a = (React.createElement("div", null));
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试使用 TypeScript JS API 做同样的事情时,我无法让它工作。我运行node然后运行这些命令:
var ts = require('ntypescript');
src = 'var a = (<div></div>);'
d = []; // for diagnostics
compilerOptions = {jsx: 'react', module: ts.ModuleKind.CommonJS};
res = ts.transpile(src, compilerOptions, 'test.tsx', d);
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
'var a = (<div></div>);\n'
Run Code Online (Sandbox Code Playgroud)
此外,d它是一个空数组,因此没有报告任何诊断消息(即错误)。是什么赋予了?
在我的 iOS 应用程序中,我打开了一个UIDocumentMenuViewController. 当我使用UIDocumentPickerModeImport模式调用它时,一切正常(我的所有 iCloud 权限都已设置)。
UIDocumentPickerModeExportToService但是,当我使用 调用它时,应用程序崩溃并出现以下错误:
断言失败 -[UIDocumentMenuViewController initWithDocumentTypes:inMode:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.6.22/UIDocumentMenuViewController.m:71
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIDocumentMenuViewController initWithDocumentTypes:inMode:] 只能以导入或打开模式调用”
我究竟做错了什么?为什么只能在导入或打开模式下调用?
我的代码:
UIDocumentMenuViewController *exportMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.image"]
inMode:UIDocumentPickerModeExportToService];
exportMenu.delegate = self;
[self presentViewController:exportMenu animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这发生在模拟器和我测试过的两个设备上(都运行 iOS 10)。
任何帮助将不胜感激!
我在div中有一个图像.我使用CSS变换将图像缩放到原始大小的2.5倍.这有效,但它覆盖了包含div.我希望它留在包含div中,这可能吗?
<html>
<script language="javascript">
function zoom()
{
var myLayer = document.getElementById('layer');
var myPhoto = document.getElementById('photo');
myPhoto.style["-webkit-transform-origin"] = "50% 50%";
myPhoto.style["-webkit-transform"] = "scale(2.5)";
}
</script>
<body onload="zoom();">
<div id ="layer" style="height:700px; width:1000px; background-color:yellow; text-align: center; vertical-align: middle;" onClick="javascript:toggleZoom();"><img id="photo" src="http://farm1.static.flickr.com/42/77156587_fa5aef2c4c_o.jpg" width="500" height="332"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有一个NSScrollView,其documentView是一个巨大的NSView,由许多子NSImageViews组成,他们在地图中充当瓷砖.(整个地图是NSView,因为它比屏幕大小大,所以它嵌入在滚动视图中).
我能够使用正确的平铺位置显示地图,并使用条形/手势滚动.但是..当我启用放大倍率才能进行缩放时,会发生以下情况:
不知怎的,我假设自动布局添加下面的瓷砖边框,我不知道如何禁用它们.这些肯定是边界,因为我已经检查了数千次我的瓷砖和子视图大小相同..所以它来自哪里?我对iOS开发有很多经验,但是我完全迷失了NSScrollView(我的委托方法在哪里?).如何禁用滚动视图的此行为?
这是我的子视图代码:
- (void)setupSubViews
{
NSLog(@"--------Creating subviews!-------");
//first we create the subviews..
//This is the key part, we traverse from top Left, and since OS X coordinates start at bottom left, we need to invert the rows!
for (int i=0; i< NUMBER_OF_COLUMNS; i++) {
for (int j=NUMBER_OF_ROWS-1; j>=0; j--) {
CGRect frame = CGRectMake(i*256, j*256, 256, 256);
NSImageView *newView = [[NSImageView alloc] initWithFrame:frame];
newView.focusRingType = NSFocusRingTypeNone; //I gave this focusRing a try, it didn't work :(
[self addSubview:newView]; …Run Code Online (Sandbox Code Playgroud) ios ×3
objective-c ×3
appkit ×1
arrays ×1
cocoa ×1
crash ×1
css ×1
ios11 ×1
javascript ×1
kerning ×1
macos ×1
methods ×1
nsscrollview ×1
nsstring ×1
properties ×1
reactjs ×1
ruby ×1
syntax ×1
transform ×1
transpiler ×1
typescript ×1
uikit ×1
webkit ×1
wkwebview ×1
xcode4 ×1