ios - 如何通过单击 UIButton IOS7 来设置 UILabel 的值

标签 ios drop-down-menu uibutton

在我的应用程序中,当用户从菜单中选择选项时,我的应用程序创建了一个下拉菜单,所选选项必须在 UILabel 框中可见。为此,我在 UIbutton 上保留了一个 UILabel 框,并且我已将 UIButton 更改为向下箭头符号,以便用户知道该选项在那里。

当用户单击箭头时,UIView 会以 POPUP 的形式出现,就像 UIView 中的下拉菜单一样,我保留了三个 UIButton如果用户选择特定按钮名称的按钮,该按钮名称将显示在顶部的 UILabel 框中。为此,每当用户根据必须将值设置为 UILabel 的标签单击选项时,我已经为 Options UIButtons 设置了标签我已经尝试过这种方法它不起作用。

我的代码。

- (void) showPopView1
  {
    self.popup.alpha = 1;
   [self.popup setFrame:CGRectMake(100, 150, 150, 150)];
  }
- (IBAction)click:(id)sender {
     [self showPopView1];
     if([sender tag] == 1){   
option.text = @"You Pressed Button 1";

     }
       else if([sender tag] == 2){
       option.text = @"You Pressed Button 2";      
   }
   }

我已经使用上面的代码来完成该任务,但它不起作用,请告诉我我做对了还是哪里做错了。我的输出屏幕。

enter image description here

最佳答案

试试这个:

- (IBAction)click:(id)sender {
     [self showPopView1];

     UIButton *red = (UIButton*)[self.popUp viewWithTag:1];
     [red addTarget:self action:@selector(colorSelected:) forControlEvents:UIControlEventTouchUpInside];

     UIButton *blue = (UIButton*)[self.popUp viewWithTag:2];
     [red addTarget:self action:@selector(colorSelected:) forControlEvents:UIControlEventTouchUpInside];

    }

-(void)colorSelected : (UIButton*)sender{

     if([sender tag] == 1){   
option.text = @"You Pressed Button 1";

     }
       else if([sender tag] == 2){
       option.text = @"You Pressed Button 2";      
   }
   }

关于ios - 如何通过单击 UIButton IOS7 来设置 UILabel 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23472673/

相关文章:

ios - [UIViewAnimationStateanimationDidStop :finished:]: message sent to deallocated instance

ios - Firebase云设备到设备推送通知设备 token 与主题

javascript - 如何处理 ul 和 li 制作的同一类下拉菜单

ios - UIButton - 文本被截断

iphone - 第二个 View Controller 中的 UIButton - Touch Up Inside 不起作用(Touch Down 确实如此)

ios动态单元格高度由照片和文字决定

ios - 从数组返回对象属性的总值

android - 单击图像创建下拉菜单

jquery - 填充对具有绝对定位的下拉菜单有意想不到的影响

ios - 如何在 UIButton 的 prepareForInterfaceBuilder 上检索 titleLabel?