gpt4 book ai didi

objective-c - uibutton,放置“目标”和“ Action ”

转载 作者:行者123 更新时间:2023-12-01 19:20:08 25 4
gpt4 key购买 nike

我有以下代码在UIToolbar(postoInfo)上添加了UIBarButtonItem类型的按钮:

UIImage *faceImage = [UIImage imageNamed:@"informazioni.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];

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

face.bounds = CGRectMake( 0, 0, 30, 30 );
[face setImage:faceImage forState:UIControlStateNormal];

buttonOne = [[UIBarButtonItem alloc] initWithCustomView:face];

NSArray *buttons = [NSArray arrayWithObjects: buttonOne, nil];

[postoInfo setItems: buttons animated:YES];

我会在按下按钮时调用一个方法,
以下行,但不起作用:
[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];

最佳答案

您现在应该为UIButton提供正确的frame属性,因为它具有CGRectZero:

face.frame = CGRectMake( 0, 0, 30, 30 ); 

Cocoa: What's the difference between the frame and the bounds?

关于objective-c - uibutton,放置“目标”和“ Action ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10775208/

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