Home > Net >  How can I add two images (one at the left and one on the right side) in a button in Xcode programati
How can I add two images (one at the left and one on the right side) in a button in Xcode programati

Time:04-08

func setupButtonUI() {
if let detailsImage = UIImage(named: "detalji_icon") {
    setImage(detailsImage, for: .normal)
    contentHorizontalAlignment = .left
    contentVerticalAlignment = .center
 
}

if let arrowImage = UIImage(named: "posalji_zahtev_black_icon") {
    setImage(arrowImage, for: .normal)
    contentHorizontalAlignment = .right
    contentVerticalAlignment = .center
}

}/this is one of the things I tried, but whit this I get only the second image and its set in the center not right and the left image is hot even there/

CodePudding user response:

UIButton has only one imageView, you can create custom button like in this answer https://stackoverflow.com/a/43112735/13628690

CodePudding user response:

Found the next solution: Made a custom UIView and added two images and label as a subview of customView. Did the constraints programaticly. Just added UITapGestureRecognizer (addGestureRecognizer) at the entire view and its all elements are clickable. The design and functionality are satisfied.

  • Related