gpt4 book ai didi

iphone - 无论方向如何,如何在 UITableViewCell 中将 UIImageView 居中?

转载 作者:可可西里 更新时间:2023-11-01 03:25:45 25 4
gpt4 key购买 nike

我尝试使用以下代码在 UITableViewCell 中将 UIImageView 横向居中:

        // self.cover_image is a UIImage variable
// cell is a UITableCellView

UIImageView* backcover_imageview = [[[UIImageView alloc] initWithImage:self.cover_image] autorelease];
[backcover_imageview sizeToFit];

//center image
//float xPos = cell.contentView.frame.size.width - (self.cover_image.size.width/2);

//TODO: need better solution
//Eyeballing attempt:
float xPos = self.cover_image.size.width - 25;
CGRect bookcover_frame = backcover_imageview.frame;
bookcover_frame.origin.x = xPos;
backcover_imageview.frame = bookcover_frame;
backcover_imageview.tag = 9000;
backcover_imageview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

[cell.contentView addSubview:backcover_imageview];

无论 iPad 或 iPhone 设备的方向如何,我都试图将 UIImageView 置于 UITableCellView 的中心。有人知道正确的方法吗?

最佳答案

我又添加了两个自动调整大小的蒙版,使用你的代码和 PengOne 的回答得到了很好的结果:

playImage.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[cell.contentView addSubview:playImage];
playImage.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);

关于iphone - 无论方向如何,如何在 UITableViewCell 中将 UIImageView 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6381731/

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