2010-07-01 11 views
2

다른 버튼을 만들고 backgroundImage로 사진이있는 배열로 초기화했습니다.버튼에서 backgroundImage의 이름을 가져 오는 방법은 무엇입니까?

UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[myButton setBackgroundImage:[UIImage imageNamed: (NSString*) obj ] forState:UIControlStateNormal]; 
[myButton addTarget:nil action:@selector(buttonDown:) forControlEvents:UIControlEventTouchUpInside]; 

Here's 내의 buttonDown-방법 :

-(void) buttonDown:(UIButton*) sender { 
NSLog(@"pressed: %@", sender.currentBackgroundImage );} 

나에게 그 추적 "을 누르면 : <가있는 UIImage : 0x6625c40>"

지금 내가 것을 얻을 수있는 방법을 알고 싶어요 클릭 한 버튼의 이미지 이름? 알아두면 좋을 것입니다. 시간 내 주셔서 감사합니다.

답변

5

UIImage는 포함하고있는 이미지의 이름을 저장하지 않으므로 사용자가 할 수 없습니다. Button 또는 이미지와의 관계에서 직접 다른 곳에 이름을 저장해야합니다.

관련

+0

감사합니다. 저는 UIButton의 하위 클래스를 만들고이를위한 새로운 메서드를 추가했습니다. 그 힌트 주셔서 감사합니다 .. – geforce

6

내가 UIbutton의 배경 imageName가 가려고하는 방법은, 해당 이미지 이름의 titleUIButton의 동일한 설정 YESbutton labelhidden property을 설정합니다.

button.titleLabel.text=[imageArray objectAtIndex:index]; 
button.titleLabel.hidden=YES; 
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

buttonTapped

,

UIButton *button=(UIButton*)sender; 

NSLog(@"The button title is %@",sender.titleLabel.text); 
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Tapped Is" message:sender.titleLabel.text delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
//[alert show]; 

워킹 벌금 (I는 iCarousel를 사용 하였다).

관련 문제