ios - 更改 UIView 按钮操作

标签 ios uiview uibutton

我有一个带有三个按钮的 View 。

当按下其中任何一个时,它会调用一个带有另一个按钮的自定义 UIView。

我想做的是将自定义 View 按钮更改为不同的操作,具体取决于调用新 View 的按钮。

希望这是有道理的。

谢谢

最佳答案

我建议您为自定义 View 动态创建按钮:

CGRect buttonFrame = CGRectMake( 10, 280, 100, 30 );
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"My Button" forState: UIControlStateNormal];
[self.view addSubview: button];
if(//clicked button 1)
 {
     [button addTarget: self 
           action: @selector(action1:) 
 forControlEvents: UIControlEventTouchDown];
 }
 else if(//clicked button 2)
 {
     [button addTarget: self 
           action: @selector(action2:) 
 forControlEvents: UIControlEventTouchDown];
 }
else
 {
     [button addTarget: self 
           action: @selector(action3:) 
 forControlEvents: UIControlEventTouchDown];
 }

关于ios - 更改 UIView 按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13200425/

相关文章:

ios - 如何从 Apple Watch 获取传感器数据到 iPhone?

ios - 如何检测 UIview 失去焦点或在 swift 4 中获得焦点?

ios - 呈现自定义模态视图时,如何在背景中显示 "fade out"控件的颜色?

ios - 如何在按下按钮时切换隐藏标签?

ios - 自定义 UIView 中的动画更改

objective-c - 对齐不同大小的图像

ios - 模拟 iPhone 5 的黑条 - Xcode

iphone - 构建 iPhone View - 就特定问题寻求帮助 + 一般建议

ios - 在 Swift 中使用标签

ios - 如何制作双线边框的UIButton?