简体   繁体   中英

image of UIbutton is stretched in iOS

I have added a right bar button in my navigation bar, and then assign image to the UIButton and set the size to 20px * 20px

the view is good in editor, but when I run the app in simulator, the image is very stretched, can anyone help me please

image is here

在此处输入图片说明

在您的UIButton ,设置button.image.contentMode = UIViewContentModeScaleAspectFit

Control Click and Drag from Button to View Controller as IBOutlet

override func viewDidLoad(){
yourButtonOutletName.image.contentMode = .ScaleAspectFit

//        
}

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