小编Cli*_*gas的帖子

iPhone SDK:透明视图中的非透明子视图

我有一个已添加到我的UIView的子视图.这个想法是子视图是一个带有uibutton的悬停面板.子视图的alpha值为0.2,因为用户需要能够看到它背后的内容.

问题是,当我向子视图添加uibuttons时,它们会从子视图继承alpha(我希望按钮是非透明的,并且alpha为1.0).我试图通过迭代uibuttons并将其alpha设置回1.0而没有成功来解决这个问题.解决方案?

    // Create the subview and add it to the view
    topHoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    topHoverView.backgroundColor = [UIColor blackColor];
    [topHoverView setAlpha:0.2];
    [self.view addSubview:topHoverView];

    // Add button 1
    button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button1 setFrame:CGRectMake(20, 10, 80, 30)];
    [button1 setTitle:@"New" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
    [topHoverView addSubview:button1];

    // Add button 2
    button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button2 setFrame:CGRectMake(120, 10, 80, 30)];
    [button2 setTitle:@"Clear" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside];
    [topHoverView addSubview:button2];

    // Add button 3
    button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; …
Run Code Online (Sandbox Code Playgroud)

iphone

11
推荐指数
2
解决办法
8324
查看次数

标签 统计

iphone ×1