👩🏻‍💻 iOSun
article thumbnail

위와 같은 클릭 UIButton이 있다.

 

 

button image를 오른쪽으로 이동

button.semanticContentAttribute = .forceRightToLeft

 

 

button image scale 변경

button.setPreferredSymbolConfiguration(.init(scale: .large), forImageIn: .normal)

 

 

전체 코드 (code base)

import UIKit

class ViewController: UIViewController {
    
    private lazy var button: UIButton = {
        let button = UIButton()
        button.setTitle("클릭", for: .normal)
        button.setTitleColor(.black, for: .normal)
        button.setImage(UIImage(systemName: "cursorarrow.click"), for: .normal)
        button.tintColor = .black
        button.semanticContentAttribute = .forceRightToLeft
        button.setPreferredSymbolConfiguration(.init(scale: .large), forImageIn: .normal)
        return button
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setConstraintsLayout()
    }
    
    private func setConstraintsLayout() {
        button.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(button)
        NSLayoutConstraint.activate([
            button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
    
}
profile

👩🏻‍💻 iOSun

@iosun

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

profile on loading

Loading...