cfi*_*her 0 cocoa cocoa-touch objective-c ios
在运行时创建新的UIButton并设置其titleLabel的文本后,仍然不显示按钮的文本.
我究竟做错了什么?
-(IBAction) cloneMe: (id) sender{
if (!currentY) {
currentY = [sender frame].origin.y;
}
UIButton *clone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect cloneFrame = [sender frame];
cloneFrame.origin.y += currentY + cloneFrame.size.height + 30;
clone.frame = cloneFrame;
[clone titleLabel].text = @"I'm a clone";
[[sender superview] addSubview:clone];
currentY = cloneFrame.origin.y + cloneFrame.size.height;
}
Run Code Online (Sandbox Code Playgroud)
Sim*_*ker 12
你需要:
[clone setTitle:@"I'm a clone" forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
查看UIControlAPI文档以获取forState:参数的其他有效值.
| 归档时间: |
|
| 查看次数: |
4555 次 |
| 最近记录: |