2017-05-01 5 views
1

저는 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) 

    } 
} 
+1

맞춤 머리 글자를 만드는 것이 좋습니다. izer. –

답변

1

아래이 시도 :

여기에 코드

를 입력
extension UIButton { 

func createRectangleButton(buttonPositionX: Double, buttonPositionY: Double ,buttonWidth: Double, buttonHeight: Double, buttonTilte: String) { 
       let button = self // changes made here 
       button.frame = CGRect(x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight) 
       button.setTitle(buttonTilte, for: .normal) 
       button.backgroundColor = COLOR_WHITE 
       button.tintColor = COLOR_BLACK 
      } 
+0

작동! 고마워요! :) –

+0

멋진! 환영합니다. – KKRocks

+0

이 대답입니까? – KKRocks