저는 iOS/Swift의 초보자이며 스토리 보드없이 간단한 응용 프로그램을 만들려고합니다. UIButton
확장 프로그램을 만들고 내보기에 간단한 버튼을 추가하고 싶습니다. 나중에 제약 조건이 설정됩니다. 버튼이 보이지 않습니다. 누군가 나를 도와 주시면 감사하겠습니다. 감사합니다.스위프트 3 : ViewController에 UIButton 확장을 추가하십시오.
--- Buttons.swift ---
extension UIButton {
func createRectangleButton(buttonPositionX: Double, buttonPositionY: Double ,buttonWidth: Double, buttonHeight: Double, buttonTilte: String) {
let button = UIButton(type: .system) as UIButton
button.frame = CGRect(x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight)
button.setTitle(buttonTilte, for: .normal)
button.backgroundColor = COLOR_WHITE
button.tintColor = COLOR_BLACK
}
}
--- InitialViewController.swift ---
import UIKit
class InitialViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Gradient Layer
view.addGradientBackground(colorTop: COLOR_ROYALRED2, colorBottom: COLOR_ROYALRED1)
// Button
let startButton = UIButton()
startButton.createRectangleButton(buttonPositionX: 50, buttonPositionY: 20, buttonWidth: 200, buttonHeight: 50, buttonTilte: "START")
self.view.addSubview(startButton)
}
}
맞춤 머리 글자를 만드는 것이 좋습니다. izer. –