gpt4 book ai didi

ios - UIButton 图像在模拟器上工作但不在设备上

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:00 24 4
gpt4 key购买 nike

我有一个应用程序,其中有一个以编程方式创建的 UITableView 填充的 UIButtons。下面的代码显示了如何创建一个 UIButton

它在模拟器上运行良好,但在设备上运行不佳。在模拟器上,按钮显示为 buttonImage.png,但在设备上没有图像。按钮的所有其他方面都是正确的。

据我所知,图像已正确添加到资源中。有什么想法吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
if (cell ==nil)
{
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0,0,160, 160)];
[button setBackgroundImage:[UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"arial" size:20];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"button" forState:UIControlStateNormal];

//more buttons created as needed

NSMutableArray *buttonArray = [[NSMutableArray alloc] init];
[array addObject:button];
//more buttons added to array as needed

[cell addSubview:[buttonArray objectAtIndex:indexPath.row]];

return cell;

最佳答案

检查您的图像名称,因为模拟器不区分大小写,但设备区分大小写。

关于ios - UIButton 图像在模拟器上工作但不在设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21726785/

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