HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 自定义视图,看起来像UIAlertView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要的东西看起来像UIAlertView(相同的背景透明而不是全屏),阻止其他UI部分,并有一些自定义内容.
这个自定义内容是:两个带标签的复选框和两个底部的YES / NO按钮.

对UIAlertView进行子类化或自定义看起来并不实用(参见this answer)并且它很危险(Apple可以拒绝代码).我正在虑创建自己的自定义UIView(可能使用UIViewController),但我不知道如何让它看起来像UIAlertView.我的意思是我想让它改变它的外观依赖于iOS版本(iOS7).

更新:
我可以放弃os版本依赖,它会很好,但这是附加功能.
主要的问题是:有没有一种很好的方法来制作这样的视图,看起来和感觉像UIAlertView没有大量的工作?直接定制UIAlertView看起来既复杂又危险.

解决方法

我创建了自己的自定义视图,看起来像iOS UIAlertView 7.使用该技术,您可以为iOS 6和iOS 7创建自定义警报.
为此,我在我的UIViewController的xib文件中创建了一个UIView:

我为这个视图添加了一些@property:

// Custom iOS 7 Alert View
@property (nonatomic,weak) IBOutlet UIView *supportViewPopup; // My UIView
@property (nonatomic,weak) IBOutlet UIView *supportViewPopupBACkground; // The grey view
@property (nonatomic,weak) IBOutlet UIView *supportViewPopupAction; // The white view with outlets
// Property for customize the UI of this alert (you can add other labels,buttons,tableview,etc.
@property (nonatomic,weak) IBOutlet UIButton *buttonOK;
@property (nonatomic,weak) IBOutlet UIButton *buttonCancel;
@property (nonatomic,weak) IBOutlet UILabel *labelDescription;

在我的viewDidLoad上:

- (void)viewDidLoad
{
    [super viewDidLoad];

       // Support View
    self.supportViewPopupAction.layer.cornerRadius = 5.0f;
    self.supportViewPopupAction.layer.masksToBounds = YES;

    // Add Support View
    [self.view addSubview:self.supportViewPopup];

    // Center Support view
    self.supportViewPopup.center = self.view.center;

    // Alpha
    self.supportViewPopup.alpha = 0.0f;
    self.supportViewPopupBACkground.alpha = 0.0f;
    self.supportViewPopupAction.alpha = 0.0f;
}

显示弹出窗口的操作:

- (IBACtion)displayPopup
{
    // Support View
    self.supportViewPopup.alpha = 1.0f;
    self.supportViewPopupBACkground.alpha = 0.5f;

    // Animation
    [UIView animateWithDuration:0.5f
                     animations:^{
                         self.supportViewPopupAction.alpha = 1.0f;
                     }];
}

解雇Popup的行动:

- (IBACtion)dismissModal
{
    // Animation
    [UIView animateWithDuration:0.5f
                     animations:^{
                         self.supportViewPopup.alpha = 0.0f;
                         self.supportViewPopupBACkground.alpha = 0.0f;
                         self.supportViewPopupAction.alpha = 0.0f;
                     }];
}

因此,您可以使用按钮,表格视图,标签,集合视图等配置您想要的supportViewPopupAction …

我花时间写了这个警报视图的例子.我希望这能帮到您 !

大佬总结

以上是大佬教程为你收集整理的ios – 自定义视图,看起来像UIAlertView全部内容,希望文章能够帮你解决ios – 自定义视图,看起来像UIAlertView所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。