ios开发button点击弹出提示,代码怎么写?
2个回答
展开全部
按钮代码
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];
}
不懂的追问
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];
}
不懂的追问
追问
那面 那部分按钮代码写在 哪个函数里面?.h文件里要怎么写?,还弹不出来?
追答
按钮写在viewdidload
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询