简体   繁体   English

如何制作这样的自定义模态uiview?

[英]How to make custom modal uiview like this?

I need some modal view on iPhone app where I will display few labels, one UIImageView and two buttons. 我需要iPhone应用程序上的一些模态视图,我将显示几个标签,一个UIImageView和两个按钮。 Design needs to be whole custom. 设计需要完全定制。 Is this custom UIAlertView? 这是自定义的UIAlertView吗? How to make something similar? 如何制作类似的东西?

UIView在Tweetboot中

There is a nice blog post by Jeff LaMarche about how to create a custom Alert View. Jeff LaMarche有一篇关于如何创建自定义警报视图的好文章。 You can take inspiration from there. 你可以从那里获取灵感。

http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html

** UPDATE on April 24, 2017 ** Unfortunately the blog doesn't exist anymore. ** 2017年4月24日更新**不幸的是,博客不再存在。 However you can retrieve the post from the Web Archive: https://web.archive.org/web/20160430051146/http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html 但是,您可以从Web存档中检索帖子: https ://web.archive.org/web/20160430051146/http: //iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html

You can acquire that simply following the following steps 只需按照以下步骤即可获得

  1. Create UIview (ViewA)of size 320*480 , so that it will cover whole screen of iPhone with background set to clearColor.This will serve as super view for our purpose; 创建尺寸为320 * 480的UIview(ViewA),使其覆盖iPhone的整个屏幕,背景设置为clearColor。这将作为我们目的的超视图;
  2. Create another UIView (ViewB) of size 320*480 with background color set to black and opacity to 40%. 创建另一个大小为320 * 480的UIView(ViewB),背景颜色设置为黑色,不透明度设置为40%。 3.Now you can add any view on ViewB. 3.现在可以在ViewB上添加任何视图。
  3. Now add ViewB to ViewA. 现在将ViewB添加到ViewA。

Finally you can Present this view where ever required. 最后,您可以根据需要提供此视图。 The effect will be, ViewA will cover the Background viewController, ViewB will server as suppressing effect for background view controller and views on B are the UIElement you will see. 效果将是,ViewA将覆盖Background viewController,ViewB将服务器视为背景视图控制器的抑制效果,B上的视图是您将看到的UIElement。

See the source for Tapku library. 查看Tapku库的源代码。 They have this option - you can always hack/tweak source code for it. 他们有这个选项 - 你可以随时破解/调整它的源代码。 Its not that difficult though, Just a lot of layer magic going around (eg the vignette effect). 虽然它并不困难,但是很多层魔法都在四处传播(例如晕影效果)。 and most of the assets are images. 而且大多数资产都是图像。 You just need to break it down properly. 你只需要妥善分解它。

Making a view like this is simple. 这样看是很简单的。 You just need to create a custom view with the pieces that you want and just make it hidden or set the alpha to 0.0. 您只需要创建一个包含所需部分的自定义视图,然后将其隐藏或将alpha设置为0.0。 Then un-hide it when you want to use it. 然后在您想要使用它时取消隐藏它。

To prevent interaction with other items behind the view put a blank semi-transparent view right behind your custom view. 为防止与视图后面的其他项目进行交互,请在自定义视图后面放置一个空白的半透明视图。

        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"\n\Please wait. \n Authorising Credentials..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];   
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
        NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"smile.png"]];
        UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
        [imageView setImage:bkgImg];
        [bkgImg release];
        [path release];
        [alert addSubview:imageView];
        [imageView release];
        [alert addButtonWithTitle:@"Cancel"];
        [alert show];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM