Search code examples
ioscocoa-touchrubymotion

How to set iOS UITextField border color? (RubyMotion + iOS)


How to use RubyMotion to set a textField border color?

Example code:

textField = UITextField.alloc.init
textField.borderStyle = UITextBorderStyleLine

The border color shows up as the Apple default color; I want it to be red.

This is using RubyMotion, not Objective-C


Solution

  • Use the Quartz framework.

    In your Rakefile:

    app.frameworks << 'QuartzCore'
    

    To set the layer attributes:

    textField.layer.borderColor = UIColor.redColor.CGColor
    textField.layer.borderWidth = 1
    textField.layer.masksToBounds = true