【问题标题】:Image as the titleView for NavigationBar图像作为 NavigationBar 的 titleView
【发布时间】:2015-09-18 14:46:01
【问题描述】:

我正在尝试使用以下代码将 titleView 设置为名为“navigationProfileView”的 UIView

            navigationProfileView.contentMode = UIViewContentMode.ScaleAspectFit
            navigationProfileView.autoresizingMask = UIViewAutoresizing.FlexibleHeight
            navigationItem.titleView = navigationProfileView
            navigationItem.titleView?.clipsToBounds = true

navigationProfileView 是一个 UIView 子类,其 UIImageView 受限于 navigationProfileView 边界。 navigationProfileView 在其 awakefromNib() 中被强制为 44x44 像素。我将在 imageView 中上传的图像非常大。

这就像一个魅力,除非我在风景中。图像按长度拉伸。谁能帮我弄清楚它为什么会伸展以及如何修复它?

谢谢, 沙布里

【问题讨论】:

    标签: ios swift uinavigationbar ios9


    【解决方案1】:

    原因是imageView的内容模式。如果将 imageView 的内容模式设置为 aspectFit。在视图中的 imageView 上使用 aspectFit 模式,图像不应拉伸。

    【讨论】:

    • 好主意,但我确实有适合图像视图的内容模式方面。在我看来,navigationProfileView 是被拉伸的。
    猜你喜欢
    • 2020-02-18
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    相关资源
    最近更新 更多