2015-08-31 80 views
0

我正試圖在iPhone上創建以下按鈕而沒有成功。iPhone UIButton在一側和圓角處有陰影/邊框

我已經看到了stackoverflow中的答案,但我無法得到相同的結果。

它基本上是一個簡單的顏色和底部的陰影,繼續圓角。

image

+0

簡單的就是用圖像。你是否試圖以編程的方式做到這一點?如果是這樣,請查看'drawRect:'繪圖並在狀態更改時重新繪製。 –

回答

2

嘗試使用photoshop製作此按鈕。並使用該圖像作爲將backgroundImage爲您的按鈕

0

圓角半徑可以通過執行實現這一目標:

self.button.layer.cornerRadius = yourDesiredRadius; 

邊框是有點難以實現。我建議你只需使用一個圖像,並將其用作按鈕的背景圖像。 您可以在Interface Builder中設置背景圖像。或者,以編程方式:

UIImage *image = [UIImage imageNamed:@"imageName"]; 
[self.button setImage:image forState:UIControlStateNormal]; 
-1

老實說,最好的辦法做這種按鈕的使用背景圖片用於正常狀態,並強調國家:

self.setBackgroundImage(UIImage(named: "buttonBackground"), forState: UIControlState.Normal) 
self.setBackgroundImage(UIImage(named: "pressedButtonBackground"), forState: UIControlState.Highlighted) 

這是他們將如何看: enter image description here

enter image description here

下面是藍色基調兩個圖像:

buttonBackground.pdfpressedButtonBackground.pdf

如果你想利用這些圖像的任何尺寸,你可以切片相似圖片如下:

enter image description here

enter image description here