Error in "Adding the Labels to the Screen"


Seems to me that:

  • (void) drawHypnoticMessage:( NSString *) message

is missing a statement to set up the frame’s size.

When the example is run as-is, nothing happens. 20 text UILabels fail to appear.
Setting breakpoint in drawHypnoticMessage, the origin of the label is set randomly, but the size is width=0, height=0
So labels are created, but they are of zero size.

With the addition of the following:

frame.size=CGSizeMake(240, 30);

the code works as advertised in the book.


Setting up the frame’s size is taken care of by [messageLabel sizeToFit];.
It resizes the label’s frame to just fit the text inside.