ios开发button点击弹出提示,代码怎么写?

2025-05-19 06:24:46
推荐回答(1个)
回答1:

按钮代码
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton setTitle:@"求最佳哦~" forState:UIControlStateNormal];

[myButton setTitle:@"可以松手~" forState:UIControlStateHighlighted];

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

myButton.backgroundColor = [UIColor yellowColor];

myButton.bounds = CGRectMake(0, 0, 200, 100);

myButton.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);

[self.view addSubview:myButton];

按钮响事件函数

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

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"按钮点击提示" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

[myAlertView show];

}

不懂的追问