How to create custom UIAlertView in iphone application

I have an application for iphone, and when I click a button, it should open its own presentation of warnings, showing the text and an X in the upper right window, as we have in the lightbox in any web application.

+6
source share
5 answers
+2
source

If you want to implement the Configure alert View then you should use this sample code, which has a very attractive collection of alert views using the ViewController. Try this sample code https://github.com/eaigner/CODialog

+1
source

Here is an example of how to create your own class that acts like a warning, but you can put any background / button graphics you want:

http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html

+1
source
- (void)willPresentAlertView:(UIAlertView *)alertView; - (void)didPresentAlertView:(UIAlertView *)alertView; 

in any of the posts above, check the subviews and their class and change the values ​​as you wish. see this sample code for UIActionSheet. find the classes of all components using ns log and customize your wish class. This is the uiaewsheet code

 for (UIView* view in [actionSheet subviews]) { NSLog(@"%@",[view class]); if ([[[view class] description] isEqualToString:@"UIAlertButton"] && [view respondsToSelector:@selector(setAlpha:)]) { [view setAlpha:2.0]; [view setOpaque:YES]; if ([view respondsToSelector:@selector(title)]) { NSString* title = [view performSelector:@selector(title)]; if ([title isEqualToString:@"Cancel"] && [view respondsToSelector:@selector(setBackgroundImage:forState:)] && [view respondsToSelector:@selector(setFrame:)] && [view respondsToSelector:@selector(setFrame:)] && [view respondsToSelector:@selector(setTitleColor:forState:)]) { [view setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [view setBackgroundImage:[UIImage imageNamed:@"btn-cancel.png"] forState:UIControlStateNormal]; [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+10, view.frame.size.width,view.frame.size.height)]; } } } } 
0
source

You can expand this component, it is available on containers, so it’s pretty easy to do it.

https://github.com/tellmarket/TAlertView/stargazers

0
source

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


All Articles