早上好。我正在尝试使用Swift编写自定义键盘,键盘的关键点是我想要使用的自定义字体。字体在xcode中工作,问题不在于它的设置。由于我使用Swift很新,我不知道如何做到这一点。这是我的代码:
let buttonTitles1 = ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"]
let buttonTitles2 = ["A", "S", "D", "F", "G", "H", "J", "K", "L"]
let buttonTitles3 = ["CP", "Z", "X", "C", "V", "B", "N", "M", "BP"]
let buttonTitles4 = ["CHG", "SPACE", "RETURN"]
let row1 = createRowOfButtons(buttonTitles1)
let row2 = createRowOfButtons(buttonTitles2)
let row3 = createRowOfButtons(buttonTitles3)
let row4 = createRowOfButtons(buttonTitles4)
self.view.addSubview(row1)
self.view.addSubview(row2)
self.view.addSubview(row3)
self.view.addSubview(row4)
row1.translatesAutoresizingMaskIntoConstraints = false
row2.translatesAutoresizingMaskIntoConstraints = false
row3.translatesAutoresizingMaskIntoConstraints = false
row4.translatesAutoresizingMaskIntoConstraints = false
addConstraintsToInputView(self.view, rowViews: [row1, row2, row3, row4])
}
func createRowOfButtons(buttonTitles: [NSString]) -> UIView {
var buttons = [UIButton]()
var keyboardRowView = UIView(frame: CGRectMake(0, 0, 320, 50))
for buttonTitle in buttonTitles{
let button = createButtonWithTitle(buttonTitle as String)
buttons.append(button)
keyboardRowView.addSubview(button)
}
addIndividualButtonConstraints(buttons, mainView: keyboardRowView)
return keyboardRowView
}
说实话,我甚至不知道在哪里更改字体。我应该在buttonTitles1
部分的createRowOfButtons
部分或之后的部分进行此操作吗?
感谢。