13

I have a problem with CATextLayer cleaning. and with iOS the solution is:

textLayer.contentsScale = UIScreen.mainScreen.scale

But I can't found "scale" property on cocoa NSScreen

Note: Answer with Object-C or Swift are OK.

3 Answers 3

15

[[NSScreen mainScreen] backingScaleFactor] will give you the scaling factor for main display

3
  • I don't have Macbook retina, so I can't test your answer, please help me test on retina. On Macbook no retina [[NSScreen mainScreen] backingScaleFactor] = 1.
    – Giau Huynh
    Commented Jul 8, 2015 at 8:29
  • 1
    This API returns 2 if its a retina display
    – sac
    Commented Jul 8, 2015 at 9:42
  • You can put any Mac into HiDPI mode for testing: cocoamanifest.net/articles/2013/01/…
    – Frank R.
    Commented Jul 9, 2015 at 9:06
6

I'm not sure it's the same as on iOS but NSScreen has backingScaleFactor, which might do the trick.

1
  • I don't have Macbook retina, so I can't test your answer, please help me test on retina. On Macbook no retina [[NSScreen mainScreen] backingScaleFactor] = 1.
    – Giau Huynh
    Commented Jul 8, 2015 at 8:28
2

swift 4.2:

(NSScreen.main?.backingScaleFactor)!

Your Answer

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

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