简体   繁体   中英

Image as the titleView for NavigationBar

I am trying to set the titleView to be an UIView called "navigationProfileView using the following code

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

navigationProfileView is a UIView subclass with a UIImageView that is constrained to navigationProfileView bounds. The navigationProfileView is forced to be 44x44 px in its awakefromNib(). The Image that I will upload inside the imageView is really big.

This works like a charm, except when I am in landscape. The image stretches Length wise. Can anyone help me figure out why it stretches and how it can be fixed?

Thanks, Shabri

The reason for this is the content mode of the imageView. If you set the content mode of the imageView to be aspectFit. With aspectFit mode on the imageView within your view, the image should not stretch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM