【发布时间】:2012-07-21 09:22:31
【问题描述】:
我是 iPhone 新手,
xpos=30;
ypos=40;
for(int i=0;i<[MyArray count];i++)
{
if(i!=0)
{
if (i%4==0)
{
ypos+=180;
xpos=30;
}
else
{
xpos+=200;
}
}
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xpos, ypos, 110.0, 130.0);
[button setImage: [UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsMake(ypos, xpos, 0.0, 0.0)];
[button setTitle:[NSString stringWithFormat:@"%@", [MyArray objectAtIndex:i]] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.view addSubview:button];
}
我可以看到按钮,但在 UIButton 上看不到我的文字。
我们将不胜感激。
【问题讨论】:
-
我认为由于您的 xpos 和 ypos,您在按钮上的文字不可见。可能会失焦。
-
删除这个 > [button setTitleEdgeInsets:UIEdgeInsetsMake(ypos, xpos, 0.0, 0.0)];并尝试 agian。
-
您的标题插图似乎比按钮的大小大得多。这使您在 te 按钮内的标题没有可用像素。
-
不是因为 setImage 函数。看我的回复。插图可能是问题,但真正的问题不是那个。
-
@waheeda:真的很感谢你。你教会了我一些新东西:)