gpt4 book ai didi

ios - 当我使用圆角时,UIImageView 图像被拉伸(stretch)。

转载 作者:行者123 更新时间:2023-11-29 11:34:41 25 4
gpt4 key购买 nike

我正在使用 UITableViewCell 作为 UITableView header 。我正在使用以下代码为 UIImageView 制作圆角。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(section==0){

static NSString *simpleTableIdentifier = @"ContactDetailsHeaderTableViewCell";

ContactDetailsHeaderTableViewCell *cell = (ContactDetailsHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];


if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactDetailsHeaderTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];

}

..................
.................

UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];

//rounded corners
cell.profilePicImgView.clipsToBounds = YES;

UIGraphicsBeginImageContextWithOptions(cell.profilePicImgView.bounds.size, NO, 1.0);

// Add a clip before drawing anything, in the shape of an rounded rect
[[UIBezierPath bezierPathWithRoundedRect:cell.profilePicImgView.bounds
cornerRadius:60.0] addClip];
// Draw your image
[img drawInRect:cell.profilePicImgView.bounds];

// Get the image, here setting the UIImageView image
cell.profilePicImgView.image = UIGraphicsGetImageFromCurrentImageContext();

// end drawing
UIGraphicsEndImageContext();


.............
.............
}

下面是输出

enter image description here

UIImageView 中的图像正在拉伸(stretch),如果我没有使用圆角,那么图像看起来是正确的。我已经尝试了很多来自 StackOverflow 的代码示例,但它们都不起作用。

最佳答案

您的代码中的一个问题是您使用 dequeueReusableCellWithIdentifier 将 header 出队。您应该改用 dequeueReusableHeaderFooterViewWithIdentifier,并将标题 View 基于指定的类 UITableViewHeaderFooterView。它们是单独的类,并且在您导航 TableView 时以不同方式回收。

关于ios - 当我使用圆角时,UIImageView 图像被拉伸(stretch)。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50410088/

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