多个UIButton没有显示

时间:2016-08-06 14:44:17

标签: ios objective-c uibutton

每当我编写一个UIButton时,它就会出现,但是当我编码时,其中一个UIButton没有显示出来。有什么我做错了吗?

var t = document.getElementById("infoBits");
 var d = t.getElementsByTagName("tr")[0]; 
var bits = d.getElementsByTagName("td"); 
for (var i = 0; i < bits.length; i++) { 
var pos = 0; 
//pass i as argument
var opac=0;
var id = setInterval(frame(i), 100);
 function frame(a){
 if (opac == 1) {
 clearInterval(id);
 } else { 
opac += 0.1; 
bits[a].style.opacity += 0.05; } 
}
 }

2 个答案:

答案 0 :(得分:0)

我尝试了你的代码它没有显示第二个按钮。你为按钮添加框架和其他东西不是为了安全的第二个按钮编码。我改变并检查代码。现在它工作正常。

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(respringPressed) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Respring Device" forState:UIControlStateNormal];
button.frame = CGRectMake(30,-25,250,250);
button.titleLabel.font = [UIFont systemFontOfSize:30];
button.backgroundColor = [UIColor yellowColor];
[self.view addSubview:button];

UIButton *safe = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[safe addTarget:self  action:@selector(safePressed) forControlEvents:UIControlEventTouchUpInside];
[safe setTitle:@"Respring Device" forState:UIControlStateNormal];
safe.frame = CGRectMake(20,300,250,250);
safe.titleLabel.font = [UIFont systemFontOfSize:30];
safe.backgroundColor = [UIColor redColor];
[self.view addSubview:safe];

我使用模拟器运行。它显示两个按钮。请参阅下面的屏幕截图

enter image description here

答案 1 :(得分:0)

你这样做是个错误!您使用“按钮”而不是“安全”尝试修改您的代码,不要忘记将按钮的Y位置更改为正值:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(respringPressed)
 forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Respring Device" forState:UIControlStateNormal];
button.frame = CGRectMake(300,30,250,250);
button.titleLabel.font = [UIFont systemFontOfSize:30];
[self.view addSubview:button];

UIButton *safe = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[safe addTarget:self  action:@selector(safePressed)
 forControlEvents:UIControlEventTouchUpInside];
[safe setTitle:@"Respring Device" forState:UIControlStateNormal];
safe.frame = CGRectMake(200,100,250,250);
safe.titleLabel.font = [UIFont systemFontOfSize:30];
safe.backgroundColor = [UIColor redColor];
[self.view addSubview:safe];