Custom view that looks like UIAlertView

I need something similar to UIAlertView (the same background is transparent, not full screen), blocks other parts of the user interface and has its own user content. This custom content: two flags with inscriptions and two YES / NO buttons at the bottom.

Subclassing or customizing the UIAlertView looks useless (see this answer ) and it is dangerous (the code may be rejected by Apple). I was thinking of creating my own UIView (possibly with a UIViewController ), but I have no idea how to make it look and feel like a UIAlertView. I want to say that I want it to change the appearance, depending on the version of iOS (iOS7).

Update : I can refuse to depend on the version of os, it would be nice, but this is an additional feature.
The main question is: is there a good way to make a look that will look and feel like a UIAlertView without a lot of work? Configuring UIAlertView directly looks complicated and dangerous.

+6
source share
4 answers

I created my own native view, similar to iOS UIAlertView 7. Using this technology, you can create custom alerts for both iOS 6 and iOS 7. To do this, I created a UIView in my xIV file of my UIViewController:

enter image description here

I added some @property for this view:

 // 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; 

In my view of DidLoad:

 - (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; } 

Action to display 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; }]; } 

Action to reject a popup:

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

So, with this, you can customize your supportViewPopupAction way you want with the buttons, table view, shortcuts, view collection, etc.

I took the time to write this example warning. Hope this helps you!

+19
source

Custom views can be transferred to PXAlertView: https://github.com/alexanderjarvis/PXAlertView

+1
source

Some components, such as UIButtons and UITextFields, will look different depending on the version, so everything will be fine, the problem that I see will be displayed in the view that it contains.

My suggestion is to discover the version in which the application is running, and then draw a warning view based on this, or simply create your own design that will fit both.

0
source

Submission of Creat depending on iOS versions!

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

Source: https://habr.com/ru/post/955032/


All Articles