Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

CHAPTER 16: Drawing with Quartz and OpenGL

583

Implementing the Action Methods

Save the nib and feel free to close the assistant editor. Now, single-click BIDViewController.m. The first thing we need to do is to import our constants file so that we have access to our enumeration values. We’ll also be interacting with our custom view, so we need to import its header as well. At the top of the file, immediately below the existing import statement, add the following lines of code:

#import "BIDConstants.h" #import "BIDQuartzFunView.h"

Next, look for the stub implementation of changeColor: that Xcode created for you, and add the following code to it:

- (IBAction)changeColor:(id)sender {

UISegmentedControl *control = sender;

NSInteger index = [control selectedSegmentIndex];

BIDQuartzFunView *quartzView = (BIDQuartzFunView *)self.view;

switch (index) {

case kRedColorTab:

quartzView.currentColor = [UIColor redColor]; quartzView.useRandomColor = NO;

break;

case kBlueColorTab:

quartzView.currentColor = [UIColor blueColor]; quartzView.useRandomColor = NO;

break;

case kYellowColorTab:

quartzView.currentColor = [UIColor yellowColor]; quartzView.useRandomColor = NO;

break;

case kGreenColorTab:

quartzView.currentColor = [UIColor greenColor]; quartzView.useRandomColor = NO;

break;

case kRandomColorTab: quartzView.useRandomColor = YES; break;

default:

break;

}

}

This is pretty straightforward. We simply look at which segment was selected and create a new color based on that selection to serve as our current drawing color. In order to keep the compiler happy, we cast view, which is declared as an instance of UIView in our superclass, to QuartzFunView. After that, we set the currentColor property so that our class knows which color to use when drawing, except when a random color is selected. When a random color is chosen, it will look at the useRandomColor property, so

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]