2010-12-17 4 views
1

오후를 변경하는은 버튼 만들기 나 아이콘 이벤트

나는 거부있어 아이 패드 앱이 - 하나를 내가 제목에 아이 패드를했고 난 단지 내 응용 프로그램에서 하나 개의 색상을 사용하고 있기 때문에 다른 있기를, 그들은 것 오, 더 좋아해.

내 앱을 사용하면 손가락으로 화면에 선을 그릴 수 있습니다. 코드로 이동하여 색상을 변경할 수는 있지만 사용자가 화면에서 색상을 변경할 수있는 버튼을 만드는 것이 좋습니다. .

나는 이것을 수행하는 방법에 대한 단서가 없습니다.

이안

답변

0

내가 당신을 돕기 위해 사랑하지만 당신은 버튼을 설정, 어떤 학습 자기를 수행해야합니다 기본적인 기술이지만 여전히 어느 정도의 지식이 필요합니다. Apple에 앱을 보내려고하기 전에 조금 더 기다리고 더 많은 것을 배우라고 조언합니다.

그러나 어떤 식 으로든 "GLPaint"라는 사과 예제를 보겠습니다. 도면의 색상을 전환하는 세그먼트 화 된 컨트롤러를 설정하여 정확히 무엇을 묻고 있습니까? 사과 예제에서 가져온 다음 코드에 초점을 맞 춥니 다.

- (void)changeBrushColor:(id)sender 
{ 
    CGFloat     components[3]; 

    // Play sound 
    [selectSound play]; 

    // Define a new brush color 
    HSL2RGB((CGFloat)[sender selectedSegmentIndex]/(CGFloat)kPaletteSize, kSaturation, kLuminosity, &components[0], &components[1], &components[2]); 
    // Defer to the OpenGL view to set the brush color 
    [drawingView setBrushColorWithRed:components[0] green:components[1] blue:components[2]]; 

} 

는 매우 간단한 예 : 분할 컨트롤러가 이른바 "changeBrushColor"에 부착되는 기능에 표정 후

// Create a segmented control so that the user can choose the brush color. 
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: 
              [NSArray arrayWithObjects: 
               [UIImage imageNamed:@"Red.png"], 
               [UIImage imageNamed:@"Yellow.png"], 
               [UIImage imageNamed:@"Green.png"], 
               [UIImage imageNamed:@"Blue.png"], 
               [UIImage imageNamed:@"Purple.png"], 
               nil]]; 

    // Compute a rectangle that is positioned correctly for the segmented control you'll use as a brush color palette 
    CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, rect.size.width - (kLeftMargin + kRightMargin), kPaletteHeight); 
    segmentedControl.frame = frame; 
    // When the user chooses a color, the method changeBrushColor: is called. 
    [segmentedControl addTarget:self action:@selector(changeBrushColor:) forControlEvents:UIControlEventValueChanged]; 
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; 
    // Make sure the color of the color complements the black background 
    segmentedControl.tintColor = [UIColor darkGrayColor]; 
    // Set the third color (index values start at 0) 
    segmentedControl.selectedSegmentIndex = 2; 

    // Add the control to the window 
    [window addSubview:segmentedControl]; 
    // Now that the control is added, you can release it 
    [segmentedControl release]; 

이 코드는 UISegmentedControl (단추 단순히 집합)를 설정한다 , 거기에서 시작하고 더 많은 질문이 있으면 다시 물어보십시오. 우리는 도와 드리려고 노력할 것입니다.

행운 샤니

+0

하이 샤니 - 감사합니다. 나는 들여다 볼 것이다. Iain –

+0

안녕하세요 Shani - 코드를 살펴본 후 코드가 잘 작동하도록했습니다. 내가 할 수없는 유일한 방법은 색칠 된 선 뒤에 이미지를 배치하는 것입니다. 나는 다양한 옵션을 시도했습니다. 나가 심상을 볼 때, 착색 한 선은 그것에 쓰지 않는다. –

+0

안녕하세요, 도와 드리겠습니다.하지만 다른 질문을 붙여 넣거나 첫 번째 질문에 추가하면 다른 답변을 붙여 넣을 수 있습니다. (이메일을 보내십시오. [[email protected]] 나는 그것에 당신을 도울 수있을 것이다) BTW, 나의 첫번째 응답이 당신을 도운 경우에, 당신은 응답으로 당신의 질문을 표시하기 위하여 표를 누를 수있다. 그렇게하면 미래에 답을 얻을 수있는 기회가 생길 것입니다. – shannoga