Changing the background color of a UIAlertView?

前端 未结 12 1148
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 03:12

I want to change the background color of my UIAlertView, but this doesn\'t appear to have a color attribute.

12条回答
  •  忘掉有多难
    2020-11-28 03:38

    Well i solved the problem in a different way. I searched for the UIImageView which contains the background image and change the image.

    ... well show is maybe not the best solution for altering the view ...

    @implementation CustomAlertView
    
    - (void)show {
        [super show];
    
        for (UIView *view in self.subviews) {
            NSLog(@"%@ with %i children", view, [view.subviews count]);
            // change the background image
            if ([view isKindOfClass:[UIImageView class]]) {
                UIImage *theImage = [UIImage imageNamed:@"password entry bg - default.png"];    
                ((UIImageView *)view).image = [theImage resizableImageWithCapInsets:UIEdgeInsetsMake(49, 8, 8, 8)];
            }
        }
    }
    
    @end
    

提交回复
热议问题