While working through examples presented by Mark and LeMarche, I have encountered a number of situations where things don't work as expected. For example, Chapter 4 discusses 'Spiffing up a button' with an image. I can't seem to get an image stretched on the button, despite the fact that I followed the original instructions and a number of work arounds [1,2,3].
How does one determine the error encountered in a Objective C method which returns void? (IMHO, a useless paradigm). Guessing at the culprit or error is a useless waste of time, and its not working well for me.
Sorry about being snippy - I am at wits end, and I am tired of all the printf's, NSLogs, and guessing. This is no way to develop programs.
Jeff
[1] Resizing an image with stretchableImageWithLeftCapWidth
[2] stretchableImageWithLeftCapWidth:topCapHeight doesn't work in initWithCoder: of UIImageView subclass
[3] iPhone stretchableImageWithLeftCapWidth only makes "D"s
// Source code from Mark and LeMarch ('Beginning iPhone 4 Programming', Chapter 4, pp. 99-100)
// added for completeness. The same code is presented in 'Beginning iPhone 3 Programming'.
// The button type is 'Custom', and the mode is 'Scale to Fill'. Trying to use TIFFs,
// removing Alpha channels, resizing buttons so their size is image.height+1, etc - no joy.
// The buttons were provided by Apple in their UICatalog example (http://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html).
// I've also tried to assign the image to a single button in case the resource cannot be shared.
// Finally, no ASSERTs fire (and no exceptions are thrown), so all should be OK (yea, right).
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* whiteButton = [UIImage imageNamed:@"whiteButton.png"];
ASSERT(whiteButton != nil);
UIImage* strechableWhiteButton = [whiteButton stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
ASSERT(strechableWhiteButton != nil);
[changeSrcFileButton setBackgroundImage:strechableWhiteButton forState:UIControlStateNormal];
[changeDestFileButton setBackgroundImage:strechableWhiteButton forState:UIControlStateNormal];
UIImage* blueButton = [UIImage imageNamed:@"blueButton.png"];
ASSERT(blueButton != nil);
UIImage* strechableBlueButton = [blueButton stretchableImageWithLeftCapWidth:12 topCapHeight:0];
ASSERT(strechableBlueButton != nil);
[changeSrcFileButton setBackgroundImage:strechableBlueButton forState:UIControlStateHighlighted];
[changeDestFileButton setBackgroundImage:strechableBlueButton forState:UIControlStateHighlighted];
}