gpt4 book ai didi

iphone - 如何为 UIButton 添加操作

转载 作者:技术小花猫 更新时间:2023-10-29 11:00:04 26 4
gpt4 key购买 nike

我是 iPhone 技术的新手。请任何人告诉我如何为 UIButton 添加操作。

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 100, 25);
btn.backgroundColor = [UIColor clearColor];
[btn setTitle:@"Play" forState:UIControlStateNormal];
[btn addTarget:self action:(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
btn.center = self.center;
[self addSubview:btn];

最佳答案

使用这个

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];

关于iphone - 如何为 UIButton 添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8341543/

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