我需要的东西看起来像UIAlertView(相同的背景透明而不是全屏),阻止其他UI部分,并有一些自定义内容.此自定义内容为:两个带标签的复选框和两个底部的YES/NO按钮.
子类或自定义UIAlertView看起来并不有用(请参阅此答案)并且它很危险(Apple可以拒绝代码).我正在考虑创建自己的自定义UIView(可能UIViewController),但我不知道如何让它看起来像UIAlertView.我的意思是我想让它改变它的外观依赖于iOS版本(iOS7).
更新:我可以放弃os版本依赖,它会很好,但这是附加功能.
主要的问题是:有没有一种很好的方法来制作这样的视图,它看起来和感觉像UIAlertView没有大量的工作?UIAlertView直接定制看起来既复杂又危险.
Jor*_*tel 19
我创建了自己的自定义视图,看起来像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;
Run Code Online (Sandbox Code Playgroud)
在我的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;
}
Run Code Online (Sandbox Code Playgroud)
显示弹出窗口的操作:
- (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;
}];
}
Run Code Online (Sandbox Code Playgroud)
解雇Popup的行动:
- (IBAction)dismissModal
{
// Animation
[UIView animateWithDuration:0.5f
animations:^{
self.supportViewPopup.alpha = 0.0f;
self.supportViewPopupBackground.alpha = 0.0f;
self.supportViewPopupAction.alpha = 0.0f;
}];
}
Run Code Online (Sandbox Code Playgroud)
因此,您可以supportViewPopupAction使用按钮,表格视图,标签,集合视图等配置您想要的...
我花时间写了这个警报视图的例子.我希望这能帮到您 !
| 归档时间: |
|
| 查看次数: |
8893 次 |
| 最近记录: |