我添加了一個自定義按鈕,並且加入了UIImage
它。自從我加入了圖像,我不能按一下按鈕,它需要3-4企圖待檢測的點擊的代碼執行。爲什麼是這樣 ?添加一個圖像按鈕,然後按一下按鈕沒有檢測
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 90.0, 150.0, 40.0);
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:button];
的buttonClick方法:
-(void)buttonClick:(id)sender {
NSLog (@"Click");
}
當你註釋掉圖像部分,做它實際上更好地工作?我想不出任何辦法的圖像會影響一個可點擊的按鈕......除非像讓你點擊錯了地方? – Ahti 2012-03-19 02:28:00
檢查customView框架。這對按鈕來說足夠大嗎? – ArunGJ 2012-03-19 04:16:02
剛剛嘗試過你的代碼,似乎工作正常,但是我做了'[self.view addSubview:button]',嘗試'self.view'並查看可點擊性是否有任何變化。 – iNoob 2012-03-19 04:27:16