在底层视图上设置阴影时,标签中的文本会变形?

发布于 2024-12-01 12:32:16 字数 1343 浏览 1 评论 0原文

我目前使用下面的代码来渲染我的分段 tableView 的视图,但

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease]; 

    headerView.backgroundColor = [UIColor colorWithRed:30/255 green:30/255 blue:30/255 alpha:1.0];
    headerView.layer.masksToBounds = NO;
    headerView.layer.shadowOffset = CGSizeMake(0, 0);
    headerView.layer.shadowRadius = 3;
    headerView.layer.shadowOpacity = 0.5;
    headerView.layer.shouldRasterize = YES;

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, headerView.frame.size.height, headerView.frame.size.width, 3)];
    headerView.layer.shadowPath = path.CGPath;

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(12, 7, tableView.bounds.size.width - 10, 20)] autorelease];
    label.font = [UIFont boldSystemFontOfSize:16];
    label.text = header;
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor blackColor];
    label.shadowOffset = CGSizeMake(0.0f, 1.0f);
    label.backgroundColor = [UIColor colorWithRed:30/255 green:30/255 blue:30/255 alpha:1.0];
    [headerView addSubview:label];

    return headerView;
}

出于某种原因,尽管文本被破坏了一点,有点扭曲?我已将其范围缩小到我在图层上施加的效果,尽管我不确定为什么这样做?

Im currently using the code below to render the view for my sectioned tableView

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease]; 

    headerView.backgroundColor = [UIColor colorWithRed:30/255 green:30/255 blue:30/255 alpha:1.0];
    headerView.layer.masksToBounds = NO;
    headerView.layer.shadowOffset = CGSizeMake(0, 0);
    headerView.layer.shadowRadius = 3;
    headerView.layer.shadowOpacity = 0.5;
    headerView.layer.shouldRasterize = YES;

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, headerView.frame.size.height, headerView.frame.size.width, 3)];
    headerView.layer.shadowPath = path.CGPath;

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(12, 7, tableView.bounds.size.width - 10, 20)] autorelease];
    label.font = [UIFont boldSystemFontOfSize:16];
    label.text = header;
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor blackColor];
    label.shadowOffset = CGSizeMake(0.0f, 1.0f);
    label.backgroundColor = [UIColor colorWithRed:30/255 green:30/255 blue:30/255 alpha:1.0];
    [headerView addSubview:label];

    return headerView;
}

For some reason though the text is being mangled a bit and a little distorted? I have narrowed it down to the effects i am putting on the layer although im not sure why its doing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难愈 2024-12-08 12:32:16

我看到您将 shouldRasterize 设置为 YES。设置光栅化比例有帮助吗?仅当您使用 iPhone 4 时才需要此操作。

 [[headerView layer] setRasterizationScale:[[UIScreen mainScreen] scale]];

I see you are setting shouldRasterize to YES. Does setting the rasterization scale help? This would only be needed if you are using an iPhone 4.

 [[headerView layer] setRasterizationScale:[[UIScreen mainScreen] scale]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文