如何自定义iOS警报视图? [英] How can I customize an iOS alert view?

查看:116
本文介绍了如何自定义iOS警报视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的iOS应用程序中创建自定义警报视图。例如,我想在 alert 中放置一些图像,并更改其颜色。

I want to create a custom alert view within my iOS application. For example, I want to put some images in this alert, and change its color.

我知道如何创建一个正常的 UIAlertView ,但是有一种方法来自定义警报视图

I know how to create a normal UIAlertView, but is there a way to customize an alert view?

推荐答案

我设置了自己的UIViewController,我一般只使用一个或两个按钮,所以我隐藏第二个按钮,如果没有使用。视图实际上是整个屏幕的大小,因此它阻挡了它后面的触摸,但它大部分是透明的,所以背景通过。

I set up my own UIViewController which I can skin with my own images. I generally only use one or two buttons, so I hide the second button if it's not being used. The view is actually the size of the entire screen, so it blocks touches behind it, but it is mostly transparent, so the background shows through.

我使用一些动画,使它像苹果的警报视图反弹。这样的工作原理:

When bringing it in, I use a few animations to make it bounce like Apple's alert view. Something like this works:

-(void)initialDelayEnded {
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
    self.view.alpha = 1.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/1.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    [UIView commitAnimations];
}

- (void)bounce1AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)];
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
    [UIView commitAnimations];
}

- (void)bounce2AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    self.view.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}

我有一个短暂的延迟内置到类中,所以initialDelayEnded是

I have the possibility of a short delay built into the class, so initialDelayEnded is called when that delay is over.

初始化时,我传递一个对象和选择器,当每个按钮被按下时,我调用,然后我调用适当的选择器上按下按钮时的对象。

When initializing, I pass in an object and selector I want called when each button is pressed, and then I call the appropriate selector on the object when a button is pressed.

这篇关于如何自定义iOS警报视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆