iphone – 以编程方式编写UIButton *** 作代码

iphone – 以编程方式编写UIButton *** 作代码,第1张

概述我正在尝试创建一个按钮,一旦点击将显示另一个UIView的d出窗口.为了测试这一点,我在viewDidLoad部分中有以下代码: - (void)viewDidLoad{ [super viewDidLoad]; self.hard1 = [UIButton buttonWithType:UIButtonTypeCustom]; [self.hard1 setFrame 我正在尝试创建一个按钮,一旦点击将显示另一个UIVIEw的d出窗口.为了测试这一点,我在vIEwDIDLoad部分中有以下代码:

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    self.hard1 = [UIbutton buttonWithType:UIbuttonTypeCustom];    [self.hard1 setFrame:CGRectMake(884,524,105,60)]; // set the x,y,wIDth and height based on your specs    UIImage *buttonImage = [UIImage imagenamed:@"green.jpg"];    hard1.layer.cornerRadius = 10;    hard1.clipsToBounds = YES;    [hard1 addTarget: self              action: @selector(buttonClicked:)    forControlEvents: UIControlEventtouchUpInsIDe];    [self.hard1 setimage:buttonImage forState:UIControlStatenormal];    [self.vIEw addSubvIEw:self.hard1];}

进一步向下:

- (IBAction) buttonClicked: (ID)sender{    NSLog(@"Tap");}

但是,当我按下按钮时,控制台不会记录“Tap”.有任何想法吗?

解决方法 观看这三行代码:

hard1.layer.cornerRadius = 10;hard1.clipsToBounds = YES;[hard1 addTarget: self          action: @selector(buttonClicked:)forControlEvents: UIControlEventtouchUpInsIDe];

你错过了自我.在这三个.他们应该是:

self.hard1.layer.cornerRadius = 10;self.hard1.clipsToBounds = YES;[self.hard1 addTarget: self          action: @selector(buttonClicked:)forControlEvents: UIControlEventtouchUpInsIDe];

此外,如果以编程方式创建它,则它不应该是IBAction(IB代表接口构建器,而不是在接口构建器中创建).

总结

以上是内存溢出为你收集整理的iphone – 以编程方式编写UIButton *** 作代码全部内容,希望文章能够帮你解决iphone – 以编程方式编写UIButton *** 作代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1084281.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存