自定义视图看起来像UIAlertView

我需要的东西看起来像UIAlertView (相同的背景透明,而不是全屏),阻止其他用户界面部分,并有一些自定义内容。 这个自定义内容是:两个带有标签的checkbox和底部的两个buttonYES / NO。

子类或自定义UIAlertView看起来不是很有用(见这个答案 ),这是危险的(代码可以被苹果拒绝)。 我想创build自己的自定义UIView (可能与UIViewController ),但我不知道如何使它看起来像UIAlertView。 我的意思是我想使它改变它的外观依赖于iOS版本(iOS7)。

更新 :我可以放弃os版本依赖,这将是很好,但这是附加function。
主要的问题是:是否有一个很好的方法来使这种看起来像UIAlertView的感觉没有大量的工作? 直接定制UIAlertView看起来很复杂和危险。

我创build了自己的自定义视图,看起来像iOS UIAlertView 7.用这种技术,你可以创build一个iOS 6和iOS 7的自定义提醒。为此,我在我的UIViewController的xib文件中创build了一个UIView:

在这里输入图像说明

我为这个视图添加了一些@property:

 // Custom iOS 7 Alert View @property (nonatomic, weak) IBOutlet UIView *supportViewPopup; // My UIView @property (nonatomic, weak) IBOutlet UIView *supportViewPopupBackground; // The grey view @property (nonatomic, weak) IBOutlet UIView *supportViewPopupAction; // The white view with outlets // Property for customize the UI of this alert (you can add other labels, buttons, tableview, etc. @property (nonatomic, weak) IBOutlet UIButton *buttonOK; @property (nonatomic, weak) IBOutlet UIButton *buttonCancel; @property (nonatomic, weak) IBOutlet UILabel *labelDescription; 

在我的viewDidLoad:

 - (void)viewDidLoad { [super viewDidLoad]; // Support View self.supportViewPopupAction.layer.cornerRadius = 5.0f; self.supportViewPopupAction.layer.masksToBounds = YES; // Add Support View [self.view addSubview:self.supportViewPopup]; // Center Support view self.supportViewPopup.center = self.view.center; // Alpha self.supportViewPopup.alpha = 0.0f; self.supportViewPopupBackground.alpha = 0.0f; self.supportViewPopupAction.alpha = 0.0f; } 

显示popup式窗口的操作:

 - (IBAction)displayPopup { // Support View self.supportViewPopup.alpha = 1.0f; self.supportViewPopupBackground.alpha = 0.5f; // Animation [UIView animateWithDuration:0.5f animations:^{ self.supportViewPopupAction.alpha = 1.0f; }]; } 

采取行动解雇Popup:

 - (IBAction)dismissModal { // Animation [UIView animateWithDuration:0.5f animations:^{ self.supportViewPopup.alpha = 0.0f; self.supportViewPopupBackground.alpha = 0.0f; self.supportViewPopupAction.alpha = 0.0f; }]; } 

所以,你可以使用button,表格视图,标签,集合视图等来configuration你的supportViewPopupAction

我花时间写这个警报视图的例子。 我希望这能帮到您 !

自定义视图可以传递给PXAlertView: https : //github.com/alexanderjarvis/PXAlertView

一些UIButtons和UITextField的组件会根据版本而有所不同,所以这样会很好,我所看到的问题将会在包含的视图中。

我的build议是检测应用程序运行的版本,然后根据该版本绘制警报视图,或者创build一个适合两者的自定义devise。

根据iOS版本创build视图!

 NSString *version = [[UIDevice currentDevice] systemVersion]; int major = [version intValue]; if (major < 7) //alert for the iOS 6 else //alert for the iOS 7