how can I have a totally transparent UIAlertView?

落爺英雄遲暮 提交于 2019-12-02 08:08:11

If you look at Apple's documentation page for UIAlertView you'll see this note:

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

In other words, Apple doesn't want developers to muck around with colors or fonts or backgrounds when it comes to UIAlertView. If Apple changes the internal guts of UIAlertView in a later iOS, your app is likely to have unexpected and not-desired effects when that modified alert appears.

If you want custom UIAlertView like behavior, why not just write your own UIView that looks and behaves a lot like UIAlertView. And then you have full control over everything about how it's drawn.

As Michael said, you can't with an UIAlertView, you have to build it yourself.

You can try BlockAlertsAnd-ActionSheets, it is like a customizable UIAlerView https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets

I know it's too late but, I'll leave this command for other developers.

.h

@interface CustomAlertView:UIAlertView {}

.m

// override
- (void)drawRect:(CGRect)rect
{
    for(UIView * sub in self.subviews)
    {
        [sub removeFromSuperview];
    }
    // this removeFromSuperview will clear all thing such as background view and buttons

    // do something
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!