【问题标题】:Autosizing didn't work with UIImageView自动调整大小不适用于 UIImageView
【发布时间】:2014-04-18 03:32:23
【问题描述】:

我有一个表格视图,我想为我的UITableviewCell 设置一个图像。我在 Storyboard 中为我的 imageView 设置了自动调整大小,但是当我在 Simulator 上运行它时,图像并没有按照我的意愿站在正确的位置。

我希望 Storyboard 中的这个支架是这样的:

但在模拟器中显示不同,如下所示:

这就是我在 TableViewCell 中设置图像的方式

@interface CBBookDetailCell : UITableViewCell
@property(weak,nonatomic) IBOutlet UIImageView *imageView;
-(void) setBookImage:(NSString*) imageLocal;
@end


@implementation CBBookDetailCell

-(void) setBookImage:(NSString*) imageLocal{
  self.imageView.image = [UIImage imageWithContentsOfFile:imageLocal];
}
…
@end

我在 CellfromIndexPath 中调用它

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellIdentifier;

    if( indexPath.row == 0){
        cellIdentifier = @"BookDetailCell";
        CBBookDetailCell *cell ;
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        [cell setBookImage:imageLocal];
        return cell;
    } else{
        cellIdentifier = @"ChapterCell";
        CBChapterCell *cell;
        CBChapter *chapter = [chapters objectAtIndex:indexPath.row-1];
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        [cell setChapterDetail:chapter.name PublishDate:chapter.publishDate];
        return cell;
    }
}

【问题讨论】:

  • 能否包含以编程方式设置图像的代码?
  • 我在上面编辑了我的问题。请看。谢谢
  • 可以包含 cellforrowatindexpath() 吗?您的 VC 中是否还有其他地方可以与 self.imageView 进行交互?
  • 我只是在 CBBookDetailCell.h 中设置了我的图像。在 cellforrowatindexpath() 中我只是调用了我的单元格。请查看我编辑的任务。

标签: ios uiimageview storyboard


【解决方案1】:

您正在调整视图本身的大小,而不是视图内部的图像。试试这个:

【讨论】:

  • 这是我已经为我的图像设置的。结果还是一样:(
猜你喜欢
  • 2014-10-20
  • 2011-05-13
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
  • 2019-08-20
相关资源
最近更新 更多