简体   繁体   中英

How can I add two images (one at the left and one on the right side) in a button in Xcode programaticly? I need also a title of a button

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 /

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

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.

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