점진적 과부하 개발 블로그

Swift UIPasteboard Class // 복사 버튼 만들기 본문

Swift

Swift UIPasteboard Class // 복사 버튼 만들기

지용빡 2022. 8. 9. 18:59
반응형
Swift UIPasteboard Class // 복사 버튼 만들기 
 

Apple Developer Documentation

 

developer.apple.com

UIPasteBoard Class 
  • 사용자가 앱 내에서 한 위치에서 다른 위치로, 그리고 앱에서 다른 앱으로 데이터를 공유할 수 있도록 도와주는 개체입니다.
선언
class UIPasteboard : NSObject
예제

  • Button(coptButton)과 Label(textLabel을 하나씩 만들어 주겠습니다.
  • copyButton 메서드를 선언해주고 UIPasteboard에 textLabel에 text값을 대입하겠습니다.
  • copyButton을 클릭하면 textLabel의 text값이 복사가 됩니다.
import UIKit

class ViewController: UIViewController {

    @IBAction func copyButton(_ sender: UIButton) {
        UIPasteboard.general.string = textLabel.text
    }
    @IBOutlet weak var textLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}
반응형

'Swift' 카테고리의 다른 글

Swift SFSafariViewController 알아보기  (0) 2022.08.26
Swift 특정 문자열 제거 및 치환  (0) 2022.08.22
Swift 메모리 안전 정리  (0) 2022.08.08
SwiftUI ProgressView  (0) 2022.08.04
Swift Localization / 다국어 처리  (0) 2022.08.02