1
我的应用程序中存在图像问题。在我的滑出菜单中,我有一个标题,其中放置了一个图像“header.png”,它存在于两个版本“header.png”和“[email protected]”中。这里是我的代码如何实现它在我的应用程序:UIView中的损失质量图像
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImage *originalImage = [UIImage imageNamed:@"header.png"];
CGSize destinationSize = CGSizeMake(320, 150);
UIGraphicsBeginImageContext(destinationSize);
[originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *headerView = [[UIImageView alloc] initWithImage:newImage];
headerView.frame = CGRectMake(0,0, 320,150);
return headerView;
}
当我我的手机(iPhone 4S),我的形象是像素化上运行的应用程序,边缘被炸飞,这不是真干净......我不知道它来自哪里。
我的图片都是72dpi的320x150px和640x300px
THX
- 编辑 -
我已经使用的UIImageView见下面的解决我的问题:
- (UIImageView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString* fileName = [NSString stringWithFormat:@"header.png"];
UIImage *newImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
UIImageView *headerView = [[UIImageView alloc] initWithImage:newImage];
headerView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 150);
return headerView;
}
感谢您的帮助,它更清晰。我对Objective-C完全陌生,所以我正在学习,我的代码没有真正优化。 – user3684398