Context:
I have a normal Document-based Cocoa Mac OS X application which uses an NSTextView for rich text input. The user may edit the font family, point size and colors of the text in the NSTextView.
Base SDK: 10.7
Deployment Target: 10.6
Question:
I would like to implement zooming of the entire UI programmatically (including the NSTextView) while the user is editing text. Scaling the frame of the NSTextView is no problem. But I don’t know how to scale the editable text inside the view which may contain multiple different point sizes in different sub-sections of the entire run of text.
How can I apply a uniform scale factor to the rich text displayed in an NSTextView?
This should play nicely with “rich text”, such that the user’s font family, color and especially point size (which may be different at different points of the run of text) are preserved, but scaled uniformly/relatively.
Is this possible given my Base SDK and Deployment targets? Is it possible with a newer Base SDK or Deployment target?
If the intent is to scale the view (and not actually change the attributes in the string), I would suggest using scaleUnitSquareToSize: method: along with the ScalingScrollView (available with the TextEdit sample code) for the proper scroll bar behavior.
The core piece from the ScalingScrollView is:
The
scale_delegateis your delegate that can adjust yourNSTextViewobject:The
scaleUnitSquareToSize:method scales relative to its current state, so you keep track of your scale factor and then convert your absolute scale request (200%) into a relative scale request.