我需要某种外观UIAlertView
(相同的背景透明且不是全屏),阻止其他UI部件并具有一些自定义内容。此自定义内容是:两个带有标签的复选框和底部的两个按钮YES / NO。
子类化或自定义UIAlertView
看起来没有用(请参阅此答案),并且很危险(Apple可能拒绝代码)。我当时正在考虑创建自己的自定义UIView
(可能使用UIViewController
),但是我不知道如何使其外观和感觉像UIAlertView。我的意思是说我想使它的外观取决于iOS版本(iOS7)。
更新:我可以放弃os版本的依赖关系,这很高兴,但这是附加功能。
主要问题是:是否有一个很好的方法可以使这种视图看起来和感觉像UIAlertView,而无需进行大量工作?UIAlertView
直接进行定制看起来很复杂且危险。
我创建了自己的自定义视图,看起来像iOS UIAlertView7。通过这种技术,您可以为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;
}];
}
撤消弹出窗口的操作:
- (IBAction)dismissModal
{
// Animation
[UIView animateWithDuration:0.5f
animations:^{
self.supportViewPopup.alpha = 0.0f;
self.supportViewPopupBackground.alpha = 0.0f;
self.supportViewPopupAction.alpha = 0.0f;
}];
}
因此,您可以supportViewPopupAction
使用按钮,表格视图,标签,集合视图等来配置所需的属性。
我花了一些时间编写此警报视图示例。我希望这能帮到您 !
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句