gpt4 book ai didi

ios - 通过完成按钮以编程方式关闭 ModalView

转载 作者:行者123 更新时间:2023-11-29 04:50:59 28 4
gpt4 key购买 nike

我必须单击“完成”按钮才能以编程方式关闭模态视图。我认为 UIButtonUIBarButtonItem 添加 UIControlEventsTouchupInside 更好。

但是对于 UIButton 我很困惑应该使用什么按钮类型。

   UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];

[button addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(dismissViewaction:)] autorelease];

最佳答案

您很可能想使用UIButtonTypeRoundedRectUIButtonTypeCustom

使用自定义类型,您可以添加图像进行显示。
您可以尝试从 UIBarButtonItem(UIBarItem 中定义的图像属性)“窃取”这些图像,并使自定义按钮看起来像 UIBarButtonSystemItemDone 按钮

UIBarButtonItem * buttonForImage = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil                                                                       action:nil] autorelease];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];

[button setImage:buttonForImage.image forState:UIControlStateNormal];

需要注意的事情。为 UIButton 设置图像时,它不会根据 contentMode 属性缩放到按钮的大小。如果您希望图像遵循 contentMode 属性的规则,请改用 setBackgroundImage: forState:

关于ios - 通过完成按钮以编程方式关闭 ModalView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853750/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com