简体   繁体   中英

How to increase the UIButton Image size in Swift3?

I am using the default UIImage property of the UIButton to set the back image . I have successfully done it but it seems that the image is appearing small. How to increase the size of the image in UIButton ?

    let viewForNavigation = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 40))
    viewForNavigation.backgroundColor = UIColor.clear
    let backbutton = UIButton(frame: CGRect(x: 0, y: 8, width: 320, height: 20))
    backbutton.setImage(UIImage(named: "back_button"), for: UIControlState.normal)
    backbutton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right:10)
    backbutton.contentHorizontalAlignment = .left
    backbutton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
    backbutton.titleLabel!.font = UIFont().robotoMedium(withFontSize: 20)
    backbutton.setTitle(title, for: .normal)

    backbutton.setTitleColor(UIColor.black, for: UIControlState.normal)
    backbutton.addTarget(self, action: #selector(exitViewController), for: UIControlEvents.touchUpInside)
    viewForNavigation.addSubview(backbutton)
    let rightBarButton = UIBarButtonItem(customView: viewForNavigation)
    self.navigationItem.leftBarButtonItem = rightBarButton

请看图片。我需要增加图像尺寸

I think you have choose wrong size back button image, please use below image for back button:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Output

在此处输入图片说明

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