在這裏我的代碼顯示4個按鈕標題哪一個圖像視圖,我想顯示點擊提醒,如果點擊按鈕標題等於UIImageview圖像。這是我的代碼,如何檢查被點擊的按鈕標題等於圖像名稱在uiimageview
imageary=[[NSMutableArray alloc]initWithObjects:@"dear.jpg",@"donkey.jpg",@"elephant.jpg",@"fox.jpg",@"giraffe.jpg",@"goat.jpg",@"buffallo.jpg",@"bull.jpg",@"cow.jpg",@"crocodile.jpg", nil]; // declare array of names not images
- (NSString *) convertToDisplayName:(NSString *)actual
{
return [actual stringByDeletingPathExtension]; //return image name without extension
}
按鈕方法
-(IBAction)methodset:(id)sender
{
int i=0;
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
mybutton = (UIButton *)view;
if(mybutton.tag == 1||mybutton.tag == 2||mybutton.tag == 3||mybutton.tag == 4)
{
i = rand() % [imageary count]; // set random image
animage.image=[UIImage imageNamed:[imageary objectAtIndex:i]];
name=[self convertToDisplayName:[imageary objectAtIndex:i]];
[mybutton setTitle:name forState:UIControlStateNormal];
NSLog(@"current image name :%@",name);
i++;
}
}
}
}
查閱即時面臨的問題與
- 蘭特(),而洗牌在該按鈕的一些值 重複。我怎樣才能在不重複的情況下保持數值,並在 UIButton中顯示。
- 我應該在哪裏比較圖片的名稱並點擊按鈕標題 是否等於或不是。請幫我解決這個問題。請做 需要。
只有點擊的按鈕標題只顯示,並且具有所有按鈕btn.title intilized相同的值 – Fazil
WER,或者說,它mybutton.title吧? – Fazil
抱歉,錯字,編輯 –