14

When using Xcode, there doesn't seem to be a way to set code editor fonts to be sharp (i.e. with no 'font smoothing). Despite what you might see in the preview area of Preferences > Fonts & Colors, inside the actual code view it’s always smoothed/anti-aliased.

There are some older questions that address previous versions of Xcode. They suggest changing various settings using defaults write com.apple.dt.Xcode <etc>, but these do not seem to affect the code view for me in Xcode 5 on Mac OS X 10.8.5. I am using a dual-display setup with one Retina and one non-Retina screen.

I've tried turning off the font smoothing checkbox in System Preferences > General > "Use LCD font smoothing where available", but that only affects sub pixel rendering...

Update (2014-11-25): The problem still occurs with Mac OS X 10.10.1 and Xcode 6.1.1. Here is a screenshot showing the editor view (smoothed) and preferences window (unsmoothed) after using these Terminal commands:

defaults write com.apple.dt.Xcode NSFontDefaultScreenFontSubstitutionEnabled -bool YES
defaults write com.apple.dt.Xcode AppleAntiAliasingThreshold 16

Xcode

Community
  • 1
  • 1
Michael Tsai
  • 1,945
  • 17
  • 41
  • added an answer for Xcode 6 & Yosemite. – Benjamin R Nov 23 '14 at 04:22
  • can you put a link to the original uncompressed, unscaled screenshot? It's not that I don't believe you, it's just that because SO has scaled the image it's actually applied anti-aliasing onto all the pixels so you can't really see the difference! – Benjamin R Nov 25 '14 at 21:17
  • It looks to me like SO has the original image. You can open it in a new browser window. – Michael Tsai Nov 26 '14 at 22:05
  • 1
    Did you try a configuration like mine with one Retina and one non-Retina display? It works fine for me with just the non-Retina display. – Michael Tsai Nov 28 '14 at 03:53
  • I'm sorry I didn't, I don't have a Retina display. – Benjamin R Nov 28 '14 at 06:04
  • @MichaelTsai. I wanted share your answer about the xcode plugin with a collegue and when he opened the page your answer was gone... May I know why you removed that answer? and how come is it even possible to delete an answer that was rewarded a bounty? – Issam T. Mar 13 '15 at 13:46
  • @IssamT. It says that moderator Bill the Lizard deleted it. No specific reason was given. Seems strange to me to delete a partial answer that could lead to a solution and leave two answers that definitely don't work. – Michael Tsai Mar 14 '15 at 14:43
  • @MichaelTsai thats very weird. thanks anyway. – Issam T. Mar 15 '15 at 16:29
  • Some fonts don't allow AA to be switched off. Menlo for example seems to be the default but always has AA, no matter what you configure. Monaco OTOH allows non-AA rendering and therefore also respects the `defaults` lines others have provided. In the Terminal, you can even see which fonts allow AA and which don't: http://apple.stackexchange.com/a/110764 – Christian Jul 08 '15 at 11:56
  • @Christian As noted above, the `defaults` command does *not* work for Monaco if you have Retina Mac with a non-Retina external display. – Michael Tsai Jul 09 '15 at 13:50
  • @MichaelTsai I don't have an Apple laptop at all so it's apparently disabled for other machine types as well. Making this machine-dependent is quite the bold move anyway but ok, I'm not gonna rant. – Christian Jul 09 '15 at 14:22
  • any solution for Xcode 9? – zumzum Aug 03 '17 at 21:27

4 Answers4

12

From Xcode9.3, text anti-aliasing can be disabled in the source editor by running the following command and restart Xcode:

defaults write com.apple.dt.Xcode SourceEditorDisableAntialiasing -bool YES

To turn anti-aliasing on again -

defaults write com.apple.dt.Xcode SourceEditorDisableAntialiasing -bool NO
Vineet Choudhary
  • 7,433
  • 4
  • 45
  • 72
7

If you use a non-retina display, try

defaults write com.apple.dt.Xcode NSFontDefaultScreenFontSubstitutionEnabled -bool YES
and restart XCode.

UPDATE:

Also invoke this:

defaults write com.apple.dt.Xcode AppleAntiAliasingThreshold 24
i_am_mushroom
  • 79
  • 1
  • 4
7

Mike Ash says that he was able to build an Xcode plug-in to tell the text view to use screen fonts. It looks like this would be straightforward to do, although I have not tried it yet.

The general strategy would be (from his tweet) would be to "patch -[NSTextView drawRect:] and do [[self layoutManager] setUsesScreenFonts: YES];."

Update (2015-08-14): Here is an explanatory blog post from Ash and the Xcode project for his plug-in. It works for me with Xcode 6.4 if I add 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 to the DVTPlugInCompatibilityUUIDs. I consider this problem solved!

Update (2016-06-20): As of Xcode 8, you cannot use Xcode plug-ins, but this user default works:

defaults write com.apple.dt.Xcode NSFontDefaultScreenFontSubstitutionEnabled -bool YES
Michael Tsai
  • 1,945
  • 17
  • 41
  • Thanks. You win my bounty ;-) Let's hope he makes a publication showing us how to use it. Also, please if you manage to fix your xcode by any mean, keep us posted by editing your answer. I will do the same if I figure it out before you do. – Issam T. Mar 12 '15 at 08:45
  • I can confirm this works for XCode 7 as well. 0420B86A-AA43-4792-9ED0-6FE0F2B16A13 is the new uuid for xcode 7. – boggy Sep 21 '15 at 00:58
  • In 7.1 it is 7265231C-39B4-402C-89E1-16167C4CC990. Had to recompile the plugin. – boggy Nov 03 '15 at 20:04
  • I am not able to get this to work with Xcode 7.2. I am adding the correct UUID to the DVTPlugInCompatibilityUUIDs array but still,even after rebuilding the project and manually adding the plugin to the correct folder, nothing happens when I restart Xcode. Any idea of what am I missing? – mttcrsp Dec 13 '15 at 23:32
  • Works for me on Xcode 7.2 without modification. As of `c57e1` it should no longer be necessary to manually supply `DVTPlugInCompatibilityUUIDs`. (Now handled by the `PBXSourcesBuildPhase` section in `project.pbxproj`.) – StvnW Jan 13 '16 at 15:18
2

I'm not sure about prior versions, but with Xcode 6.1 and Yosemite (OS X 10.10) two commands are actually required to disable anti-aliasing locally in Xcode.

First, as has already been stated, you need to enter the following at a terminal console:

defaults write com.apple.dt.Xcode NSFontDefaultScreenFontSubstitutionEnabled -bool YES

Then, secondly:

defaults write com.apple.dt.Xcode AppleAntiAliasingThreshold <some integer value>

This is preferable to disabling font smoothing or antialiasing throughout the entire operating system. It should really be an option to check/uncheck inside the program itself, but at least this works.

Benjamin R
  • 555
  • 6
  • 25
  • Thanks for trying to help, however this did not work for me. I have the font set to Monaco 9. These commands make the font look the way I want within Xcode's font preferences, but they do not seem to affect the main text editor view. – Michael Tsai Nov 24 '14 at 14:04
  • @MichaelTsai hi Michael, can you give me some more info? What's your current config? Are you now using Xcode 6.1 and Yosemite, or are you still using the same config as in your question? Can you give me a screenshot (by pressing Cmd-Shift-3 on the keyboard) while in Xcode showing the Fonts & Colors window in the foreground and the editor behind it, just so I can see what you are saying? Don't compress it, just upload the screenshot directly. – Benjamin R Nov 24 '14 at 18:24
  • I have updated the question with this additional information. – Michael Tsai Nov 25 '14 at 20:20