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

12
  • added an answer for Xcode 6 & Yosemite.
    – Benjamin R
    Nov 23, 2014 at 4: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, 2014 at 21:17
  • It looks to me like SO has the original image. You can open it in a new browser window. Nov 26, 2014 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. Nov 28, 2014 at 3:53
  • I'm sorry I didn't, I don't have a Retina display.
    – Benjamin R
    Nov 28, 2014 at 6:04

4 Answers 4

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
7
  • 1
    I confirm on High Sierra + Xcode 9.4.1 (restart Xcode needed)
    – Trevor
    Sep 19, 2018 at 16:36
  • @Trevor Thanks, Updated :) Sep 20, 2018 at 7:55
  • 1
    not working in mojave, works on high siera with Xcode 10 Oct 31, 2018 at 10:25
  • 1
    @АндрейПервушин - just checked on Mojave and Xcode 10 - WORKSFORME
    – silverdr
    Dec 6, 2018 at 23:31
  • 1
    xcode 11.3.1, mojave 10.14.6 - it doesn't work for me. Honestly, it is so f***ng frustrating!!!
    – boggy
    Jan 26, 2020 at 2:17
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
4
  • 1
    Thanks. Unfortunately, that doesn't work with my mixed-resolution dual-display setup. Oct 1, 2013 at 17:02
  • Thanks; you are my hero! Works great in Xcode 5 with Mavericks on Mac Pro.
    – lifjoy
    Oct 23, 2013 at 0:30
  • Doesn't work on my MacBook Pro 2012 (non-Retina) with Xcode 5.0.2 and OS X 10.9.1
    – Aldrich Co
    Feb 13, 2014 at 1:47
  • Works on non-retina display Dell P2416D (2560x1440), Xcode 7.3 on OS X 10.11 El Capitan. Jun 21, 2016 at 7:44
7
+50

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
5
  • 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, 2015 at 8: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, 2015 at 0:58
  • In 7.1 it is 7265231C-39B4-402C-89E1-16167C4CC990. Had to recompile the plugin.
    – boggy
    Nov 3, 2015 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, 2015 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, 2016 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.

3
  • 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. Nov 24, 2014 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, 2014 at 18:24
  • I have updated the question with this additional information. Nov 25, 2014 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.