2011-11-20 81 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链接会为你的风格的工作需要。

相关问题