2016-05-30 17 views
0

我有一个PNG图像,我会插入到我的导航标题。从对象c UIImage到swift和图像大小不好

在对象C我

UIImage *image = [UIImage imageNamed:@"logo_up.png"]; 
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image]; 

    CGRect screenBound = [[UIScreen mainScreen] bounds]; 
    CGSize screenSize = screenBound.size; 
    CGFloat screenWidth = screenSize.width; 
    CGFloat screenHeight = screenSize.height; 

它工作得很好,我的形象是高品质

然后创建在迅速类似的APP,使用相同的图像,并写这样的代码

self.navigationItem.titleView = UIImageView(image: UIImage(named: "icons/logo_up.png")) 
     self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor() 

     self.navigationController?.navigationBar.frame.size.width = 320 
     self.navigationController?.navigationBar.frame.size.height = 44 

它打印我的图像,但质量很差。 我创建不同大小的图像,但没有任何变化。此APP中的每张图片质量都很差。 我使用PNG和JPG扩展名。

回答

1

试着玩你的内容模式UIImageView。您正在更改Swift示例中的UINavigationBar的框架,通过这样做可以降低图像质量。

let imageView = UIImageView(image: UIImage(named: "icons/logo_up.png")) 
imageView.contentMode = .ScaleAspectFit //change contentMode 
self.navigationItem.titleView = imageView 
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()    self.navigationController?.navigationBar.frame.size.width = 320 
self.navigationController?.navigationBar.frame.size.height = 44 
+0

同样的问题...质量形象很差,我不明白为什么 –