按钮标题被裁剪。为什么?

时间:2017-03-18 18:15:19

标签: swift3

我有按钮和Picker View。如果我试图在Picker View中选择项目并使用Button的文本,那么它会裁剪文本。为什么呢?

这是我的代码:

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource
{

let array = ["Incredible", "Fantastic"]

@IBOutlet weak var pickerView: UIPickerView!
@IBOutlet weak var button: UIButton!

override func viewDidLoad()
{
    super.viewDidLoad()

    pickerView.delegate = self
    pickerView.dataSource = self
}

override func didReceiveMemoryWarning()
{
    super.didReceiveMemoryWarning()
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
    return array.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
    button.setTitle(array[row], for: .normal)
    return array[row]
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat
{
    return 50
}

func numberOfComponents(in pickerView: UIPickerView) -> Int
{
    return 1
}
}

Device emulator& amp;屏幕截图XCODE的故事板:

enter image description here

enter image description here

0 个答案:

没有答案