在 Xcode 4 中更改鼠标的 i 型光标
在 Xcode 4 中使用深色配色方案时,i 形光标(又名文本选择光标)几乎看不见。有没有办法改变这个光标的颜色,无论是专门针对 Xcode,还是在系统范围内?
如果它也能自动更改为与其背景形成对比的颜色,那就太好了。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从 Xcode 8 开始,Apple 将 i-beam 光标隐藏在无人发现的地方。相反,许多人选择使用 Mousecape 来更改所有程序中的工字梁。我更喜欢这种方法,因为它修复了其他支持深色主题的程序(例如 Komodo 编辑器)中的 i-beam。 Mousecape 应该适用于所有 Xcode 版本,并且更新 Xcode 不会破坏光标。我目前在 macOS 10.13.2、Xcode 9.1 中使用 Mousecape。步骤如下:
Mousecape.app
文件>进口海角>上面下载的“cape”文件
应用
Mousecape >安装助手工具
原始答案:
Xcode 并不像我发现的每个人都在谈论的那样使用系统范围的 i-beam 光标它说得好像这是一个已知的事实。如果我不相信那些人,我就不会花两天时间弄清楚如何通过 编辑CoreGraphics却发现Xcode的ibeam没有改变。
顺便说一句,我还偶然发现了如何编辑其他系统光标。
我花了一个周末的大部分时间来解决这个问题,但是 Xcode 中的 i-beam 光标可以编辑。对于 Xcode 3.2.6(我认为是更早的版本,但尚未测试),它只是位于以下位置的 TIFF 文件:
Xcode 4.1 具有相同的文件,但它不会影响主编辑器中的 i-beam(我假设它在某处使用,但可能没有) 。相反,Xcode 4.1 中的主编辑器使用此文件:
ibeam 文件在 Xcode 4.4 中再次移动:
编辑 DVTIbeamCursor.png 足以更改我系统上主编辑器中的 i-beam。在另一个网站上,有人报告 [email protected] 将用于视网膜显示屏或 Apple 的其他新型高分辨率显示屏比如迅雷和电影院。谁知道 TIbeam.tiff 是否不再使用,因为他们没有将其更新为 png。
根据下面的评论,在 Xcode 5.0.2 中,所有 3 个光标文件都被替换为一个文件:
在 5.1.1 中(男孩,他们肯定喜欢在几乎每个版本中进行更改,不是吗?):
我猜测该文件是双分辨率(又名视网膜显示)光标,针对非视网膜屏幕缩小了。
如果您在 Xcode 中找不到 ibeam 文件,请尝试在终端中运行以下命令:
在 Xcode 7.3 中,光标被移动到以下捆绑文件内,因此上面的搜索命令找不到它:
我建议使用找到的进程 此处将新光标修补到捆绑文件中。如果您不喜欢它安装的光标(我觉得它仍然太暗,灰色轮廓与灰色注释文本混合在一起),请按照以下步骤操作:
/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
Assets.car
复制到可以编辑的地方,例如至于~/Documents/Assets.car
。Theme Engine.app
,单击打开文档
,然后打开~/Documents/Assets.car
。DVTIbeamCursor
。Assets.car
移回/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
并保留备份将修改后的版本复制到某处,这样您就不必再次执行此操作,直到新的 Xcode 版本更改了Assets.car
中的内容。您可能还希望向 Apple 发送一封愤怒的信,抱怨他们在过去 7 年多的时间里没有解决这个问题,反而让用户越来越难以修补 Apple 损坏的光标。
不要忘记保留已编辑光标的备份。较新的 Xcode 版本在进行软件更新时将用默认光标覆盖您的自定义光标。
这是我使用的 ibeam 光标: 右键单击 ibeam 并选择保存图像以获取png 版本,或点击此处下载 tiff 版本。
如果您要制作自己的光标,请注意原始光标中黑线相交的位置就是我光标中白线相交的位置。这是因为原始光标是在白色背景上使用的,所以它的黑色部分是光标热点所在的位置。
As of Xcode 8, Apple has hidden the i-beam cursor somewhere where nobody has found it. Instead, many have chosen to use Mousecape to alter the i-beam in all programs. I prefer that method since it fixes the i-beam in other programs that support dark themes, such as Komodo editor. Mousecape should work in all Xcode versions and updating Xcode won't break the cursor. I'm currently using Mousecape in macOS 10.13.2, Xcode 9.1. Here are the steps:
Mousecape.app
File > Import Cape > "cape" file downloaded above
Apply
Mousecape > Install Helper Tool
Original answer:
Xcode does NOT use the system-wide i-beam cursor as everyone I found talking about it stated as if it was a known fact. If I hadn't believed those people, I wouldn't have spent two days figuring out how to alter the system i-beam cursor by editing CoreGraphics only to find that Xcode's ibeam doesn't change.
BTW, I also stumbled on how to edit other system cursors.
I spent most of a weekend figuring this out, but the i-beam cursor in Xcode CAN be edited. It's simply a TIFF file in the following location for Xcode 3.2.6 (and earlier, I assume, but have not tested):
Xcode 4.1 has the same file but it does not affect the i-beam in the main editor (I assume it's used somewhere, but maybe not). Instead, the main editor in Xcode 4.1 uses this file:
The ibeam files have moved again in Xcode 4.4:
Editing DVTIbeamCursor.png was enough to change the i-beam in the main editor on my system. On another site, someone reported that [email protected] will be used on a retina display or Apple's other new high res displays like Thunderbolt and Cinema. Who knows if TIbeam.tiff is even used anymore since they didn't update it to png.
According to comments below, in Xcode 5.0.2 all 3 cursor files were replaced with one file:
And in 5.1.1 (boy, they sure love to change things in almost every version, don't they?):
I'm guessing that file is a double resolution (aka retina display) cursor that's scaled down for non-retina screens.
If you can't find the ibeam file in your Xcode, try running this command in Terminal:
In Xcode 7.3, the cursor was moved inside the following bundle file so the search command above won't find it:
I recommend using a process found here to patch a new cursor into the bundle file. If you don't like the cursor it installs (I felt it was still too dark and the grey outlines blend in with grey comment text), follow these steps:
/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
Assets.car
somewhere where it can be edited, such as to~/Documents/Assets.car
.Theme Engine.app
, clickOpen Document
, then open~/Documents/Assets.car
.DVTIbeamCursor
.Assets.car
back to/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
and keep a backup copy of your modified version somewhere so you don't have to do this again until a new Xcode version changes what's inAssets.car
.You may also wish to send an angry letter to Apple to complain that they have not fixed this problem in the last 7+ years and have instead made it progressively more difficult for users to patch Apple's broken cursor.
Don't forget to keep backups of your edited cursors. Newer Xcode versions will overwrite your custom cursors with default ones when it does a software update.
Here's the ibeam cursor I use: Right click the ibeam and choose to save the image to get the png version, or click here to download the tiff version.
If you're making your own cursor, notice that where the black lines intersect in the original cursor is where the white lines intersect in my cursor. That's because the original cursor was meant to be used on a white background, so its black part is where the cursor hotspot is.
我为 ibeam 光标创建了一个 公共存储库,它应该适用于浅色和深色背景,因为它是黑色的,带有白色的轮廓。它包括简洁的说明和一个可以放入 Xcode 包中的 TIFF 文件。
更新:git 存储库包含一个 shell 脚本,使安装变得非常容易。
I created a public repo for an ibeam cursor that should work on light and dark colored backgrounds, because it is black with a white outline. It includes succinct instructions, and a TIFF file ready to drop in to the Xcode bundle.
Update: the git repo includes a shell script that makes installation quite easy.
不幸的是,这是 Carbon 和 Cocoa 光标之间的区别 — Cocoa 光标不会反转;至少,到雪豹为止。在 Lion 中,甚至 Carbon 光标的行为也与您不想要的一样。
例如,如果您有一台运行 Snow Leopard 或更早版本的计算机,请比较 BBEdit 或 TextWrangler(使用 Carbon 光标)中的 I-beam 行为;它会在黑色背景上变成全白色。即使这样也有点脆弱——当我改变屏幕放大倍数时,BBEdit 以前的白色光标变成了黑色。
您仍然可以在 Cocoa 应用程序中设置 Carbon 光标。在 NSTextView 子类中尝试一下:(
在 64 位中,您会看到该函数被排除在标头之外,但该符号在那里并且可以工作。)如果您有足够的动力,您可以修补 Xcode 来执行一些变体上述内容可能来自 Xcode 插件。
如果你使用的是 Lion,它应该是这样的:
所以我建议提交一个错误与 Apple 合作,使系统范围的 I 型光标(或一般的 NSCursor)正确处理深色背景;这不是 Xcode 特有的问题,几年前就应该修复了。
Unfortunately this is a difference between Carbon and Cocoa cursors—Cocoa cursors won't invert; at least, up to Snow Leopard. In Lion, even Carbon cursors behave like you don't want.
If you've got a machine running Snow Leopard or earlier, compare the I-beam behavior in BBEdit or TextWrangler (which use Carbon cursors), for example; it'll become entirely white on a black background. Even this is a bit fragile—when I change the screen magnification, BBEdit's formerly-white cursor becomes black.
You can still set a Carbon cursor in your Cocoa app. Try this in a NSTextView subclass:
(In 64-bit you'll see that this function is excluded from the headers, but the symbol is there and works.) If you're sufficiently motivated, you could potentially patch Xcode to do some variant of the above, perhaps from an Xcode plugin.
If you're on Lion, here's what it is supposed to look like:
So I'd suggest filing a bug with Apple to make the systemwide I-beam cursor (or NSCursor in general) properly handle dark backgrounds; it's not an Xcode-specific issue and it should really have been fixed years ago.
对于 Xcode 5 预览,我为深色模板创建了更好的 I-Beam。您可以自由使用它。
http://www.scigems.org/wordpress/?p=92
For Xcode 5 preview, i have created a better I-Beam for Dark color templates. You can use it freely.
http://www.scigems.org/wordpress/?p=92
根据苹果论坛上的这个帖子:
https://discussions.apple。 com/thread/2811447?start=0&tstart=0
XCode 4 字体和颜色首选项中提到的“光标颜色”实际上是您在单击窗口以输入文本。
当您在代码编辑窗口中移动鼠标时看到的 I 形光标是 Mac-OS 范围内的功能,您无法在 XCode 中更改该功能。
上面的论坛帖子建议寻找第三方软件来更改系统范围工字梁光标的属性。
另一篇文章指出,您至少可以编辑光标大小以使其更加明显:
系统偏好设置 ->普遍接入 ->鼠标和触控板 ->光标大小
According to this thread on the Apple forums:
https://discussions.apple.com/thread/2811447?start=0&tstart=0
the "cursor color" referred to in the XCode 4 fonts and colors preferences is actually the cursor you see when you have clicked in a window to enter text.
The I-beam cursor you see when you are moving the mouse around in the code editing window is a Mac-OS wide feature which you cannot change in XCode.
The forum post above suggests looking for third party software to change attributes of the system-wide I-beam cursor.
Another post points out that you can at least edit the cursor size to make it more visible:
System Preferences -> Universal Access -> Mouse & Trackpad -> Cursor Size