2011-11-20 31 views
-1

我想知道我怎麼可以創建自定義的UIButton用的UILabel內像這樣image我如何創建一個自定義的UIButton?

+0

從您添加的圖片中,我很難理解您在自定義UIButton中查找的自定義功能。你想要什麼?自定義顏色,字體或圖像?因爲所有這些都可以在沒有繼承UIButton的情況下實現。 –

+0

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

+0

我想添加7 UILabel與他們的價值在右上方和容器與這種風格? – GoldFire

回答

0

你可以這樣做:

int i=0; 
UIButton *customButton=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 

//Set the height of your button, that will depend on how much text you will be putting 
//inside 
[customButton setFrame:CGRectMake(3,40,315,130)]; 

for(i=0; i<7; i++){ 
    //Their position will change depending on which label you are adding 
    UILabel *leftLabel=[[UILabel alloc] initWithFrame:CGRectMake(5, 5+(17*i), 150, 12)]; 
    UILabel *rightLabel=[[UILabel alloc] initWithFrame:CGRectMake(160, 5+(17*i), 150, 12)]; 

    //Set the text for each label 
    [leftLabel setText:[NSString stringWithFormat:@"Left %d",i+1]]; 
    [rightLabel setText:[NSString stringWithFormat:@"Right %d",i+1]]; 

    //Set the backgroudn as clear to be able to see the background of your button 
    [leftLabel setBackgroundColor:[UIColor clearColor]]; 
    [rightLabel setBackgroundColor:[UIColor clearColor]]; 

    //Add those labels 
    [customButton addSubview:leftLabel]; 
    [customButton addSubview:rightLabel]; 

    //Do your memory management 
    [leftLabel release]; 
    [rightLabel release]; 
} 

的CIMGF鏈接會爲你的風格的工作需要。

相關問題