在 Xcode 4 中更改鼠标的 i 型光标

发布于 2024-11-25 01:27:02 字数 124 浏览 2 评论 0 原文

在 Xcode 4 中使用深色配色方案时,i 形光标(又名文本选择光标)几乎看不见。有没有办法改变这个光标的颜色,无论是专门针对 Xcode,还是在系统范围内?

如果它也能自动更改为与其背景形成对比的颜色,那就太好了。

With a dark color scheme in Xcode 4 the i-beam cursor (aka text selection cursor) is nearly invisible. Is there a way to change the color of this cursor, either for Xcode specifically, or failing that, system-wide?

It'd be nice if it would automatically change to a color contrasting its background too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

稚然 2024-12-02 01:27:03

从 Xcode 8 开始,Apple 将 i-beam 光标隐藏在无人发现的地方。相反,许多人选择使用 Mousecape 来更改所有程序中的工字梁。我更喜欢这种方法,因为它修复了其他支持深色主题的程序(例如 Komodo 编辑器)中的 i-beam。 Mousecape 应该适用于所有 Xcode 版本,并且更新 Xcode 不会破坏光标。我目前在 macOS 10.13.2、Xcode 9.1 中使用 Mousecape。步骤如下:

  1. 此处下载 Mousecape
  2. 下载“cape”修改后的 i-beam 光标,例如 Bright白色灰色阴影
  3. 运行 Mousecape.app
  4. 从 Mousecape 菜单栏:文件>进口海角>上面下载的“cape”文件
  5. 右键单击导入的“cape”并选择应用
  6. 检查新光标是否在Xcode中工作。满意后,您可以通过从 Mousecape 的菜单栏运行命令来在每次重新启动时应用光标: Mousecape >安装助手工具
  7. 安装 macOS 更新(例如 10.13.1 到 10.13.2)可能需要重复步骤 5 和 6。

原始答案:

Xcode 并不像我发现的每个人都在谈论的那样使用系统范围的 i-beam 光标它说得好像这是一个已知的事实。如果我不相信那些人,我就不会花两天时间弄清楚如何通过 编辑CoreGraphics却发现Xcode的ibeam没有改变。
顺便说一句,我还偶然发现了如何编辑其他系统光标

我花了一个周末的大部分时间来解决这个问题,但是 Xcode 中的 i-beam 光标可以编辑。对于 Xcode 3.2.6(我认为是更早的版本,但尚未测试),它只是位于以下位置的 TIFF 文件:

/Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

Xcode 4.1 具有相同的文件,但它不会影响主编辑器中的 i-beam(我假设它在某处使用,但可能没有) 。相反,Xcode 4.1 中的主编辑器使用此文件:

/Developer/Library/PrivateFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

ibeam 文件在 Xcode 4.4 中再次移动:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.png

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/[电子邮件受保护]

编辑 DVTIbeamCursor.png 足以更改我系统上主编辑器中的 i-beam。在另一个网站上,有人报告 [email protected] 将用于视网膜显示屏或 Apple 的其他新型高分辨率显示屏比如迅雷和电影院。谁知道 TIbeam.tiff 是否不再使用,因为他们没有将其更新为 png。

根据下面的评论,在 Xcode 5.0.2 中,所有 3 个光标文件都被替换为一个文件:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

在 5.1.1 中(男孩,他们肯定喜欢在几乎每个版本中进行更改,不是吗?):

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Re‌sources/DVTIbeamCursor.tiff

我猜测该文件是双分辨率(又名视网膜显示)光标,针对非视网膜屏幕缩小了。

如果您在 Xcode 中找不到 ibeam 文件,请尝试在终端中运行以下命令:

sudo find / -name 'Ibeam' -print

在 Xcode 7.3 中,光标被移动到以下捆绑文件内,因此上面的搜索命令找不到它:

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/Assets.car

我建议使用找到的进程 此处将新光标修补到捆绑文件中。如果您不喜欢它安装的光标(我觉得它仍然太暗,灰色轮廓与灰色注释文本混合在一起),请按照以下步骤操作:

  1. 下载最新版本的 主题引擎(我成功使用版本 1.0.0(111) 和 Xcode 7.3.1)
  2. 备份/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
  3. Assets.car 复制到可以编辑的地方,例如至于~/Documents/Assets.car
  4. 运行Theme Engine.app,单击打开文档,然后打开~/Documents/Assets.car
  5. 向下滚动左侧的项目列表并选择 DVTIbeamCursor
  6. 您应该在中心面板中看到正常分辨率和双分辨率 ibeam 光标图像。将您自己的 ibeam 图像拖动到任一光标顶部,它应该会更改以显示您的图像。我使用了 PNG 图像。
  7. 保存,然后关闭主题引擎。
  8. 将修改后的 Assets.car 移回 /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car 并保留备份将修改后的版本复制到某处,这样您就不必再次执行此操作,直到新的 Xcode 版本更改了 Assets.car 中的内容。

您可能还希望向 Apple 发送一封愤怒的信,抱怨他们在过去 7 年多的时间里没有解决这个问题,反而让用户越来越难以修补 Apple 损坏的光标。

不要忘记保留已编辑光标的备份。较新的 Xcode 版本在进行软件更新时将用默认光标覆盖您的自定义光标。

这是我使用的 ibeam 光标: In png format 右键单击​​ 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:

  1. Download Mousecape from here
  2. Download a "cape" with modified i-beam cursor such as Bright white or Grey shadow
  3. Run Mousecape.app
  4. From Mousecape's menu bar: File > Import Cape > "cape" file downloaded above
  5. Right click imported "cape" and choose Apply
  6. Check the new cursor is working in Xcode. When satisfied, you can apply the cursor on each reboot by running a command from Mousecape's menu bar: Mousecape > Install Helper Tool
  7. Installing macOS updates (such as 10.13.1 to 10.13.2) may require repeating steps 5 and 6.

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):

/Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

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:

/Developer/Library/PrivateFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

The ibeam files have moved again in Xcode 4.4:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.png

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/[email protected]

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:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

And in 5.1.1 (boy, they sure love to change things in almost every version, don't they?):

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Re‌​sources/DVTIbeamCursor.tiff

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:

sudo find / -name 'Ibeam' -print

In Xcode 7.3, the cursor was moved inside the following bundle file so the search command above won't find it:

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/Assets.car

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:

  1. Download the latest release of Theme Engine (I successfully used version 1.0.0(111) with Xcode 7.3.1)
  2. Back up /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
  3. Copy Assets.car somewhere where it can be edited, such as to ~/Documents/Assets.car.
  4. Run Theme Engine.app, click Open Document, then open ~/Documents/Assets.car.
  5. Scroll down the list of items on the left and pick DVTIbeamCursor.
  6. You should see a normal resolution and double resolution ibeam cursor image in the center panel. Drag your own ibeam image on top of either cursor and it should change to show your image. I used a PNG image.
  7. Save, then close Theme Engine.
  8. Move your modified 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 in Assets.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: In png format 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.

月隐月明月朦胧 2024-12-02 01:27:03

我为 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.

病女 2024-12-02 01:27:03

不幸的是,这是 Carbon 和 Cocoa 光标之间的区别 — Cocoa 光标不会反转;至少,到雪豹为止。在 Lion 中,甚至 Carbon 光标的行为也与您不想要的一样。

例如,如果您有一台运行 Snow Leopard 或更早版本的计算机,请比较 BBEdit 或 TextWrangler(使用 Carbon 光标)中的 I-beam 行为;它会在黑色背景上变成全白色。即使这样也有点脆弱——当我改变屏幕放大倍数时,BBEdit 以前的白色光标变成了黑色。

您仍然可以在 Cocoa 应用程序中设置 Carbon 光标。在 NSTextView 子类中尝试一下:(

#import <Carbon/Carbon.h>
[...]

- (void)resetCursorRects;
{
    // disable existing cursor setting behavior
}

- (void)cursorUpdate:(NSEvent *)event;
{
    SetThemeCursor(kThemeIBeamCursor);
}

- (void)updateTrackingAreas;
{
    for (NSTrackingArea *trackingArea in [self trackingAreas])
        [self removeTrackingArea:trackingArea];

    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];
}

在 64 位中,您会看到该函数被排除在标头之外,但该符号在那里并且可以工作。)如果您有足够的动力,您可以修补 Xcode 来执行一些变体上述内容可能来自 Xcode 插件

如果你使用的是 Lion,它应该是这样的:

Invertingcursor

所以我建议提交一个错误与 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:

#import <Carbon/Carbon.h>
[...]

- (void)resetCursorRects;
{
    // disable existing cursor setting behavior
}

- (void)cursorUpdate:(NSEvent *)event;
{
    SetThemeCursor(kThemeIBeamCursor);
}

- (void)updateTrackingAreas;
{
    for (NSTrackingArea *trackingArea in [self trackingAreas])
        [self removeTrackingArea:trackingArea];

    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];
}

(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:

Inverting cursor

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.

望喜 2024-12-02 01:27:03

对于 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

萌化 2024-12-02 01:27:03

根据苹果论坛上的这个帖子:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文