iOS 8自定義鍵盤的庫:Slidden
Slidden 是開源,可定制的,使用 Swift 編寫的 iOS 8 鍵盤。利用這個開源庫,可以方便的配置鍵位、顏色以及鍵位對應的圖片。當然,如果你想學習如何一步一步開發自定義鍵盤
Simple
If you subclass Slidden.KeyboardViewController, you get a KeyboardView
and nice autolayout constraints right out of the box. Subclassing is as easy as:
class KeyboardViewController: Slidden.KeyboardViewController { override func viewDidLoad() { super.viewDidLoad() // Add the keys we need to the keyboard setupKeys() }
Add keys to the keyboard.
func setupKeys() { let helloKey = KeyboardKeyView(type: .Character, keyCap: "Hello", outputText: "Hello") helloKey.textColor = UIColor.whiteColor() helloKey.color = UIColor.blueColor() self.keyboardView.addKey(helloKey, row: 0) let worldKey = KeyboardKeyView(type: .Character, keyCap: "World", outputText: "World") worldKey.textColor = UIColor.whiteColor() worldKey.color = UIColor.redColor() self.keyboardView.addKey(worldKey, row: 0) }
Add images to your keys.
func setupKeys() {
let shiftKey = KeyboardKeyView(type: .Shift, keyCap:"", outputText: "")
let img = UIImage(named:"Shift")
shiftKey.image = img
shiftKey.imageView.contentMode = .Center
}
If you want your image to be the same color as your other keys' text, you can use shouldColorImage
to have CoreGraphics redraw the image of your key with the uniform color.
func setupKeys() {
let shiftKey = KeyboardKeyView(type: .Shift, keyCap:"", outputText: "")
let img = UIImage(named:"Shift")
shiftKey.image = img
shiftKey.imageView.contentMode = .Center
shiftKey.color = UIColor.blueColor()
shiftKey.selectedColor = UIColor.darkerBlueColor()
shiftKey.textColor = UIColor.whiteColor()
shiftKey.shouldColorImage = true // Will redraw the Shift image to match `textColor`
}
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!