gpt4 book ai didi

iphone - UIbutton 宽度和高度为零?

转载 作者:行者123 更新时间:2023-11-28 18:01:51 25 4
gpt4 key购买 nike

我有这个

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventTouchDown];

[button setTitle:NSLocalizedString(@"Action", @"")
forState:UIControlStateNormal];
CGFloat width = button.bounds.size.width;

此时宽度为零...

零?

有什么线索吗?

最佳答案

由于没有设置UIButton的frame,修改代码为

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20,20,50,50);
[button addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventTouchDown];

[button setTitle:NSLocalizedString(@"Action", @"")
forState:UIControlStateNormal];
CGFloat width = button.bounds.size.width; // Now the width of button would be 50

关于iphone - UIbutton 宽度和高度为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14474857/

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