UIActionSheet 中的控件定位错误
当用户点击按钮时,我需要显示带有 UISwitch 和完成按钮的弹出窗口,并在点击弹出窗口中的完成按钮时保存开关的状态。
所以我使用 UIActionSheet 来做到这一点 -
sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Done", nil];
theSwitch = [[UISwitch alloc] init];
[sheet addSubview:theSwitch];
[sheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.firstOtherButtonIndex)
{
theSwitch .on? NSLog(@"Switch is on") : NSLog(@"Switch if off");
}
}
所有这些都很好。我定位有问题。不幸的是,我目前没有屏幕截图可以发布在这里。但该开关出现在与操作表标题同一行的最顶部,然后在其下方是“完成”按钮。
请有人帮助我如何将开关放置在标题下方并增加操作表大小,使其看起来整洁。我需要尽快这个。谢谢。
I need to display a pop with a UISwitch and a Done button when user taps on a button and save the state of the switch when the done button in the pop up is tapped.
So I use UIActionSheet to do this -
sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Done", nil];
theSwitch = [[UISwitch alloc] init];
[sheet addSubview:theSwitch];
[sheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.firstOtherButtonIndex)
{
theSwitch .on? NSLog(@"Switch is on") : NSLog(@"Switch if off");
}
}
All this works great. I have problem with positioning. Unfortunately, I don't have a screen shot at the moment to post here. But the switch appears at the very top on the same line with the Action Sheet title and then below that is the Done button.
Please someone help me how to position the switch below the Title and increase the Action Sheet size so it looks neat. I need this asap. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置开关的框架。
将开关放置在警报视图的中间
重要的是,在调用工作表的 showInView 之后放置开关。否则,纸张的大小为零。如果更换,可以在底部添加相同的空间。
希望这有帮助
You can set the frame of the switch.
To position the switch in the middle of the alert view
It is important, that you position the switch after calling showInView for the sheet. Otherwise the size of the sheet is zero. If you replace you can add same space to the bottom.
Hope this helps
我认为您可以选择通过修改
UISwitch
的框架来实现此目的,如上面描述的trumi
。如果您想放置一个带有图像的UIButton
here 是一个未记录的选项。没有证件,所以有被拒绝的风险。此外,您还会在同一线程中找到许多其他美化选项
I think you have the option to do it by modifying frame of
UISwitch
liketrumi
described above. If you want to place aUIButton
with image them here is a undocumented option. Undocumented, so risk of rejection.Also you will find many other beautification option in the same thread