【问题标题】:image of uitableviewcell is stretchinguitableviewcell 的图像正在拉伸
【发布时间】:2023-03-27 18:34:01
【问题描述】:

下面是我如何初始化单元格的样式

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        .................................................
        .................................................
        // Set size for imageView
        CGRect  frame               =   self.imageView.frame;
        frame.size.width            =   16;
        frame.size.height           =   16;
        self.imageView.frame        =   frame;
    }

    return self;
}

但是,在将图像设置为单元格的 imageview 之后,图像现在正在拉伸。原稿尺寸为 24x24。

如何使图像看起来像形状?

【问题讨论】:

    标签: ios objective-c uitableview uiimageview


    【解决方案1】:

    尽量不要使用单元格的 imageView 属性,而是创建自己的 imageview 并添加它

    UIImageView *myImageView = [[UIImageView alloc] initWithImage:neededImage];
    myImageView.frame = CGRectMake(0,0,16,16);
    [self addSubview:myImageView];
    [myImageView release];
    

    原来的问题是 imageView 属性是If an image is set, it appears on the left side of the cell, before any label. 所以单元格拉伸它就像它习惯的行为一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 2017-05-07
      • 2012-09-09
      • 1970-01-01
      相关资源
      最近更新 更多