2015-06-10 102 views
-4

我有一個UIButton只有一個UIImage設置,點擊(長按)圖像自動改變與陰影,我想要的是,即使按鈕被點擊,但不與長按圖像應該有陰影。我已經嘗試從IB設置UIButton屬性Reverse on HighlightShows Touch On Highlight但沒有結果點擊時顯示觸摸UIButton Objective-C

+0

你應該展示你用代碼試過了什麼? –

回答

0

這是關於UIControl Class。這是默認與陰影。所以如果你想定製它,你應該addTarget到你的按鈕到UIButton的每一個動作,如tapping,long press, touchUpInside,我認爲它不是長時間按它只是你不能意識到不同點擊。

在我的項目之一

定製我的按鈕操作是這樣的:

buyButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width*3/4-2, 0, self.frame.size.width/4+4, self.frame.size.height)]; 
    [buyButton addTarget:self action:@selector(buyButtonClicked:) forControlEvents:UIControlEventTouchDown]; 
    [buyButton addTarget:self action:@selector(buyButtonNormal:) forControlEvents:UIControlEventTouchUpInside]; 
    [buyButton addTarget:self action:@selector(buyButtonNormal:) forControlEvents:UIControlEventTouchUpOutside]; 

與此類似的方法:

- (void) buyButtonClicked:(UIButton *) sender { 
    if ([self.backgroundColor isEqual:[Util UIColorForHexColor:@"fede32"]]) { 
    self.backgroundColor = [Util UIColorForHexColor:@"fdca2e"]; 
} 
    else if([self.backgroundColor isEqual:[Util UIColorForHexColor:@"cfd3dc"]]) { 
    self.backgroundColor = [Util UIColorForHexColor:@"c0c5d0"]; 
} 

}

- (void) buyButtonNormal:(UIButton *) sender { 
    if ([self.backgroundColor isEqual:[Util UIColorForHexColor:@"fdca2e"]]) { 
    self.backgroundColor = [Util UIColorForHexColor:@"fede32"]; 
} 
    else if([self.backgroundColor isEqual:[Util UIColorForHexColor:@"c0c5d0"]]) { 
    self.backgroundColor = [Util UIColorForHexColor:@"cfd3dc"]; 
} 
[delegate purchaseOffer:selectedOffer]; 

}

如果你需要莫關於UIButton行動的信息有很多關於這個網站的問題。