Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UITableViewCell背景视图图像大小调整?_Objective C_Uitableview_Ios4_Uiimageview - Fatal编程技术网

Objective c UITableViewCell背景视图图像大小调整?

Objective c UITableViewCell背景视图图像大小调整?,objective-c,uitableview,ios4,uiimageview,Objective C,Uitableview,Ios4,Uiimageview,我使用图像显示UITableViewCell的全部内容,它是使用backgroundView属性设置的 我的问题是它总是按比例缩放以适应单元格。在这种情况下,有没有办法禁用缩放,这样我就可以只提供480像素的版本,而当方向为纵向时,它就会被裁剪 我是这样做的: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static

我使用图像显示UITableViewCell的全部内容,它是使用backgroundView属性设置的

我的问题是它总是按比例缩放以适应单元格。在这种情况下,有没有办法禁用缩放,这样我就可以只提供480像素的版本,而当方向为纵向时,它就会被裁剪

我是这样做的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
        UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.png", indexPath.row+1]]];
        UIImageView *selectedBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.selected.png", indexPath.row+1]]];    
        cell.backgroundView = bgView;
        cell.selectedBackgroundView = selectedBgView;        
        [bgView release];
        [selectedBgView release];
    return cell;
}
当方向改变时,我尝试使用两个版本的图像在它们之间切换。到目前为止,这也是可行的,但它有一个缺点,即在处理动画时,始终可以看到缩放

谢谢你的帮助

阿恩

我想是你在找什么

更多信息:

我想是你在找什么

更多信息:

我没有在模拟器或设备上尝试此操作,但以下操作可能有效:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
    // New!
    cell.backgroundView.clipsToBounds = YES;

    UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.png", indexPath.row+1]]];
    UIImageView *selectedBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.selected.png", indexPath.row+1]]];    
    // New!
    bgView.center = CGPointMake(160, 25); // Adjust the y-Value to be exactly half of the height of your cell
    bgView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; // Not quite sure whether these two will work, maybe you have to play a little with the Masks

    cell.backgroundView = bgView;
    cell.selectedBackgroundView = selectedBgView;        
    [bgView release];
    [selectedBgView release];
return cell;
}

请告诉我您是否成功地使其运行。

我没有在模拟器或设备上尝试此操作,但以下操作可能有效:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
    // New!
    cell.backgroundView.clipsToBounds = YES;

    UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.png", indexPath.row+1]]];
    UIImageView *selectedBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.selected.png", indexPath.row+1]]];    
    // New!
    bgView.center = CGPointMake(160, 25); // Adjust the y-Value to be exactly half of the height of your cell
    bgView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; // Not quite sure whether these two will work, maybe you have to play a little with the Masks

    cell.backgroundView = bgView;
    cell.selectedBackgroundView = selectedBgView;        
    [bgView release];
    [selectedBgView release];
return cell;
}

让我知道您是否成功运行了它。

设置背景图像视图的内容模式

bgView.contentMode = UIViewContentModeTopLeft;
selectedBgView.contentMode = UIViewContentModeTopLeft;

这会告诉UIImageView将其图像放在左上角,而不是将其缩放到合适的位置。

设置背景图像视图的内容模式

bgView.contentMode = UIViewContentModeTopLeft;
selectedBgView.contentMode = UIViewContentModeTopLeft;

这告诉UIImageView将其图像放在左上角,而不是按比例缩放。

不知道这一点,比我的想法聪明得多,也短得多:有时懒惰是值得的这是一个UIView属性,所以它在一些地方派上了用场。我在玩contentMode,但似乎我在错误的地方做了。谢谢,它就像一个魔咒:我不知道那个,比我的想法聪明得多,也短得多:有时候懒惰是值得的这是一个UIView属性,所以它在一些地方派上了用场。我在玩contentMode,但似乎我在错误的地方做了。谢谢,这就像一个咒语:谢谢你的回答。我来不及查看,因为我回来时已经找到了詹姆斯的解决方案。不过还是要谢谢你的帮助!谢谢我将UIViewContentModeTopLeft与clipToBounds=YES结合使用,使其在我的项目中发挥作用。感谢您的回答。我来不及查看,因为我回来时已经找到了詹姆斯的解决方案。不过还是要谢谢你的帮助!谢谢我将UIViewContentModeTopLeft与clipToBounds=YES结合使用,使其在我的项目中工作。