2013年1月30日 星期三

透明的Button (二)

使用動態產生的Button來產生透明的效果,只需要使用UIButtonTypeCustom模式就可以了,範例如下。


1. 圖檔顯示

    UIButton *aButton = [[UIButton alloc] init];
   
    aButton = [UIButton buttonWithType:UIButtonTypeCustom];
   
    [aButton setFrame:CGRectMake(100, 620, 70, 70)];
    //aButton.backgroundColor = [UIColor  redColor];
   
    [aButton setBackgroundImage:[UIImage imageNamed:@"Log Out.png"] forState:UIControlStateNormal];
   
    [aButton addTarget:self action:@selector(goBackMainViewController) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:aButton];


2. 文字顯示

    movPic *aButton = [movPic buttonWithType:UIButtonTypeCustom];
   
    if (fileIndex <9)
        aButton = [[movPic alloc] initWithFrame:CGRectMake(10 + (fileIndex%3)*300, (fileIndex/3)*200+100, 360, 170)];
   
   
    [aButton setBackgroundImage:[UIImage imageNamed:@"ballcloud2.png"] forState:UIControlStateNormal];
   
    aButton.font = [UIFont boldSystemFontOfSize:36];
   
    [aButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
   
    aButton.titleLabel.numberOfLines = 3;
   
    [aButton setTitle:[NSString stringWithFormat:@"\n%@", storyName] forState:UIControlStateNormal];
   
    aButton.tag = fileIndex;
     
    [self.view addSubview:aButton];

沒有留言: