Saya baru saja memulai aplikasi untuk iOS di Swift, saya melakukan desain secara terprogram (maksud saya, saya tidak menggunakan storyboard)
Saya memiliki UIButton dengan gambar di dalamnya, saya ingin gambar tersebut memenuhi seluruh tombol. Saat ini hanya menampilkan gambar di tombol saya, tetapi lebih kecil dari tombol, berada di tengah atas bingkai tombol.
Kode saya adalah:
let buttonLocation = UIButton(frame: CGRect(x: 0, y: 0, width: buttonRoundedSize, height: buttonRoundedSize))
buttonLocation.setImage(UIImage(named: "locate_button"), for: .normal)
buttonLocation.backgroundColor = .white
buttonLocation.layer.cornerRadius = frame.width / 2
buttonLocation.myExtension()
Berikut adalah hal-hal yang saya coba (tidak ada yang berhasil):
self.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
self.autoresizingMask = .flexibleWidth
self.autoresizingMask = .flexibleHeight
self.imageView?.contentMode = .scaleAspectFill
Jika saya hanya meletakkan baris contentMode juga tidak berfungsi. ImageView tidak kembali, nihil saya sudah memeriksanya..
Terima kasih!
buttonLocation.setBackgroundImage(UIImage(named: "locate_button"), for: .normal)
- person Rocky   schedule 24.05.2019