我有一个设置了约束的图像视图,并且我(从 URL)加载的图像由于某种原因没有填满整个图像视图。我附上了一张有问题的照片,然后是同一个“帖子”的详细视图。两者使用相同的代码。在详细视图(显示正确的视图)中,我在 viewdidload 期间设置了帖子图像,它是一个独立视图。在 wonky 中加载的是具有自定义类的表格视图单元格,并且图像设置在 cellForRowAtIndexPath 中。在将图像发送到 Back4App 并解析为 500x500 之前,我确实调整了图像大小,并且图像视图都设置为剪辑到边界和宽高比。uiimageview 约束完全相同,水平对齐为零,固定宽度和高度,以及所有四个边的约束(距离最近的邻居 8 个)
以下是它们如何完成的代码片段:
粉红色背景:
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
PostCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"PostCell"];
Post *post = self.posts[indexPath.row];
PFUser *user = post.author;
[user fetchInBackgroundWithBlock:^(PFObject * _Nullable object, NSError * _Nullable error) {
cell.usernameLabel.text = post.author.username;
}];
cell.titleLabel.text = post.caption;
cell.isLiked = NO;
NSURL *imageURL = [NSURL URLWithString:post.image.url];
[cell.imageView setImageWithURL:imageURL];
return cell;
}
一个正确加载的:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
PFUser *user = self.post.author;
[user fetchInBackgroundWithBlock:^(PFObject * _Nullable object, NSError * _Nullable error) {
self.usernameTextLabel.text = self.post.author.username;
}];
self.titleTextLabel.text = self.post.caption;
self.descriptionTextLabel.text = self.post.bodyText;
NSURL *postImageURL = [NSURL URLWithString:self.post.image.url];
[self.postImageView setImageWithURL:postImageURL];'''
}
有小费吗?可能有一些我没有掌握的基础知识 - 我基本上参加了速成课程,我只参加了大约 3 周,所以我并不像我希望的那样深入了解这些.
我已将背景颜色设置为粉红色,以便您可以看到图像大小与图像视图
旁注:我真的不知道如何正确地做代码块???我在听它说的哈哈