【发布时间】:2013-07-29 18:48:45
【问题描述】:
我正在尝试在模态视图的顶部添加一个“X”按钮,因此如果用户按下它会关闭模态视图。我看了这里提出的解决方案how to add close button to modal view corner which is presented in UIModalPresentationPageSheet?
但我在这里有两个后续问题,因为我对 ios 编程相当陌生
-
上面页面中提出的解决方案似乎对我不起作用。我首先在模态 VC 的 viewDidLoad 中使用普通按钮尝试了它,我看到它只出现在模态视图的范围内,而不是我想要的外部。
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; buttonView.backgroundColor = [UIColor brownColor]; CGRect buttonFrame = CGRectMake( 0, 0, 100, 50 ); UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame]; [button setTitle: @"Close" forState: UIControlStateNormal]; [button setTitleColor: [UIColor redColor] forState: UIControlStateNormal]; [button addTarget:self action:@selector(closeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; [buttonView addSubview: button]; CGRect parentView = self.view.superview.frame; CGRect currentView = self.view.frame; CGRect buttonViewFrame = buttonView.frame; buttonViewFrame.origin = CGPointMake(parentView.origin.x - buttonViewFrame.size.width/2.0f, parentView.origin.y - buttonViewFrame.size.height/2.0f); [buttonView setFrame:buttonViewFrame]; [self.view addSubview:buttonView];
我看到的是
- 如何绘制“X”按钮,我应该使用 CGRect 来绘制它还是在上面的示例中添加一个按钮而不是添加一个带有“X”的图像作为子视图?
提前感谢您的帮助
【问题讨论】:
-
您的模态视图控制器是否剪裁了它的子视图?如果您使用情节提要,请确认“剪辑子视图”复选框未选中。如果您以编程方式执行模态视图控制器,请将模态视图控制器的
clipsToBounds属性设置为 NO。试一试。 -
模态视图是一个表格视图控制器,它被选中,我取消选中它,我仍然看到相同的结果。我更新了原始帖子,即使在取消选中后我也看到了我所看到的图像盒子
标签: ios objective-c uiview modal-dialog