2011-08-24 30 views
1

即时通讯目前使用下面的代码来渲染切片的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; 
} 

出于某种原因,虽然文本正在被错位了一下,有些扭曲了我的看法?我把它缩小到了我正在放在图层上的效果,尽管我不知道为什么它会这样做。

回答

1

我看到你正在设置shouldRasterizeYES。设置光栅化比例是否有帮助?如果您使用的是iPhone 4,则只需要这样做。

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

是:这是正确的答案。您应该设置光栅化比例。 –