如何在iPhone应用程序中创build自定义UIAlertView
我有一个iphone应用程序和一个button,点击它应该打开一个自定义的警报视图,通过显示一些文本和右上angular的“X”十字标志窗口,因为我们在任何Web应用程序中的灯箱。
这里是链接,我认为它可以解决你的问题。
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uialertview-custom-graphics/
如果你想实现自定义警报视图,那么你应该这个示例代码具有非常有吸引力的警报视图集合在ViewController的帮助下。 试试这个示例代码链接https://github.com/eaigner/CODialog
下面是一个如何创build类似于警报视图的自定义类的示例,但是您可以放置任何您想要的背景/buttongraphics:
http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html
- (void)willPresentAlertView:(UIAlertView *)alertView; - (void)didPresentAlertView:(UIAlertView *)alertView;
在上述任何信息中,检查子视图和他们的类,并根据需要更改值。 请参阅UIActionSheet的示例代码。 使用ns日志search所有组件的类并自定义您的期望类。 这是uiaheetheet代码
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)]; } } } }
你可以扩展这个组件,它可以在pod上使用,所以很容易做到。