簡體   English   中英

如何更改iPhone上按鈕的默認顏色?

[英]How can I change the default color of the button on iPhone?

如何更改iPhone上按鈕的默認顏色?

一種常見的技術是使用圖像作為背景。 實際上你可以使用一個可伸縮的圖像:

- (void)viewDidLoad {
    UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
    UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}

原始圖片:

替代文字

最終結果:

替代文字

我發現這篇文章解釋了如何在沒有圖像和完全代碼的情況下完成此操作。

http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

希望有所幫助。

假設您的意思是UIButton ,您只能使用setTitleColor:forState:更改標題顏色setTitleColor:forState:

您無法更改背景顏色或形狀。 你必須為此創建自己的控件。

我在iphonedevsdk.com上開始了這個帖子。

希望如果不在這里,我們會得到答案。

自定義UIButtons的一個好方法是直接操作核心動畫層。 你可以找到關於“可可是我的女朋友”的好教程

http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM