acb's technical journal

Posts matching tags 'objective c'


D2UI, or data-driven interfaces in iOS

The D3 JavaScript library allows one to create and manipulate arbitrary elements on a web page from data in an elegantly declarative fashion, making it easier to implement quite sophisticated dynamic data visualisations. Recently, I was thinking about whether the ideas behind D3 could translate to iOS and Objective C, and ended up writing a small library and example application to explore the idea.


cocoa touch coreanimation d3 data visualisation ios objective c 0


Automatically sizing CATextLayer to fit

When developing on iOS, I am a big fan of CoreAnimation, and particularly the CALayer and its subclasses; they're lighter in weight than UIView, carrying less baggage, and are a quick way to display all sorts of elements in a user interface.

CALayer has a number of useful subclasses, among them CATextLayer, which displays text in an arbitrary font and size* within its bounds. One shortcoming of CATextLayer, however, is that it does not provide any means of measuring the dimensions of its contents, requiring you to guesstimate them and size the layer to fit, or else pre-measure the string before sizing your layer. This is complicated somewhat by the fact that CATextLayer can accept font settings in several forms (string font name, CoreText CTFont or CoreGraphics CGFont), none of which are the convenient UIFont object.

Having had reason to create a precisely-sized CATextLayer recently, I looked into the issue and have written a small category extending CATextLayer, adding a method for setting its bounds to neatly encompass its text.


calayer catextlayer cocoa coreanimation coretext ios objective c 0

This will be the comment popup.
Post a reply
Display name:

Your comment:

Please enter the text in the image above here: