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

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

问题描述

我想在我的 iOS 应用程序中创建一个自定义的警报视图.例如,我想在这个alert中放一些images,并改变它的颜色.

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,但是有没有办法自定义一个 alert 视图?

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.

在引入它时,我使用了一些动画使其像 Apple 的警报视图一样弹跳.像这样的工作:

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天全站免登陆