iPhone development: How to create colored or translucent background for UIActionSheet?

后端 未结 6 2252
盖世英雄少女心
盖世英雄少女心 2020-11-28 05:58

When you try deleting a note in iPhone\'s Notes application, an UIActionSheet pops up. The sheet is translucent (but not black translucent). How is that achieved? Is it p

6条回答
  •  日久生厌
    2020-11-28 06:37

    It's not too difficult. You can use the following code:

    CGSize mySize = myActionSheet.bounds.size;
    CGRect myRect = CGRectMake(0, 0, mySize.width, mySize.height);
    UIImageView *redView = [[[UIImageView alloc] initWithFrame:myRect] autorelease];
    [redView setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]];
    [myActionSheet insertSubview:redView atIndex:0];
    

    Just make sure you present the UIActionSheet before doing this or the size wont be set. That makes it kind of ugly, but you could do something like:

    [myActionSheet showInView:self.view];
    if (!redAdded) {
        redAdded = YES;
        //THE ABOVE CODE GOES HERE
    }
    

提交回复
热议问题