iOSTextfield with no border

  1. ‹ Older
  2. 3 years ago

    Christoph D

    20 Dec 2014 Pre-Release Testers, Xojo Pro

    This explains how: http://stackoverflow.com/questions/20116471/how-to-hide-uitextfield-border

  3. Dave S

    20 Dec 2014 San Diego, California USA
    Edited 3 years ago

    SWIFT version to remove border from a UITextField

    self.borderStyle=UITextBorderStyle.None

    UITextView does not have a border, but one can be added by manipulating the LAYER property
    and the same can be done for the UITextField if you wanted to CHANGE the default border

     var borderWidth:Double {
            set {
                self.layer.borderWidth=CGFloat(newValue)
                self.setNeedsLayout()
            }
            get { return Double(self.layer.borderWidth) }
        }
    
        var borderColor:UIColor {
            set {
                self.layer.borderColor=newValue.CGColor
                self.setNeedsLayout()
            }
            get { return UIColor(CGColor:self.layer.borderColor) }
        }
  4. Christoph D

    20 Dec 2014 Pre-Release Testers, Xojo Pro

    Maybe Jim can take a peek at this? ;-)

  5. Christoph D

    22 Dec 2014 Pre-Release Testers, Xojo Pro
    Edited 3 years ago

    Anyone can make this working? Changing the color should do the job. :)

  6. Dave S

    22 Dec 2014 San Diego, California USA

    As I showed above..... iOS doesn't allow you to change the border of a UITEXTFIELD, but you can turn it off, and replace it by using the LAYER property...... but I can only give you the SWIFT versions, and hopfully Michel or someone can take it from there

  7. Michel B

    22 Dec 2014 Pre-Release Testers, Xojo Pro

    @Christoph Dnbsp;Vocht Anyone can make this working? Changing the color should do the job. :)

    I know what you really want is a magic declare, but as usual, there is a pure Xojo alternative.

    Place a white rectangle 3 pix wide :

    • Left relative to TextArea left
    • Top relative to TextArea top
    • Height relative and equal to TextArea height

    Do the same for right, use a 3 pix high rectangle on top and the same at bottom.

  8. Michel B

    22 Dec 2014 Pre-Release Testers, Xojo Pro
    Edited 3 years ago

    @Dave S As I showed above..... iOS doesn't allow you to change the border of a UITEXTFIELD, but you can turn it off, and replace it by using the LAYER property...... but I can only give you the SWIFT versions, and hopfully Michel or someone can take it from there

    Am a bit tired tonight to do a declare. It is only one property, though. But I just posted a valid, tested and working pure Xojo technique.

    About Swift, I like it very much because the examples in the Apple developer library are now readable in Swift, almost as easy as the C# examples in Msdn for Windows.

  9. Michel B

    22 Dec 2014 Pre-Release Testers, Xojo Pro

    Wait wait wait...

    I was on my way to do a declare so I placed a TextArea on a view and ran that, and just as in XCode, the TextArea has NO BORDER when run. It shows a border only in the IDE !

  10. Dave S

    22 Dec 2014 San Diego, California USA

    @Michel B Wait wait wait...

    I was on my way to do a declare so I placed a TextArea on a view and ran that, and just as in XCode, the TextArea has NO BORDER when run. It shows a border only in the IDE !

    But he said iosTextFIELD not Area :)

  11. Michel B

    22 Dec 2014 Pre-Release Testers, Xojo Pro
    Edited 3 years ago

    @Dave S But he said iosTextFIELD not Area :)

    Oops. Sorry. Same suggestions as before :

    • Rectangles
    • Use a TextArea with the code I posted to make it non multiline
    • Wait for some good soul to post a declare. Won't be me. Time to go to bed.

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html#//apple_ref/occ/instp/UITextField/borderStyle

    The property to set is borderStyle. In Swift it is only one integer :

    The border style used by the text field.
    
    Declaration
    SWIFT
    var borderStyle: UITextBorderStyle

    That said, a borderless TextField will be challenging for the user to find if it is the same color as the background.

  12. Michel B

    22 Dec 2014 Pre-Release Testers, Xojo Pro

    Thanks to Urlich Bogun's UITextField project :

    Public Enum BorderStyle
    None
    Line
    Bezel
    RoundedRect
      declare Sub setBorderStyle lib "UIKit" selector "setBorderStyle:" (id as ptr, style as BorderStyle)
      
      setborderStyle(Ptr(TextField1.Handle),BorderStyle.None)

    Just to remove the border, no need for enum :

      declare Sub setBorderStyle lib "UIKit" selector "setBorderStyle:" (id as ptr, style as integer) 
      
      setborderStyle(Ptr(TextField1.Handle),0) 
  13. Christoph D

    23 Dec 2014 Pre-Release Testers, Xojo Pro

    @Michel B Thanks to Urlich Bogun's UITextField project :

    Public Enum BorderStyle
    None
    Line
    Bezel
    RoundedRect
    declare Sub setBorderStyle lib "UIKit" selector "setBorderStyle:" (id as ptr, style as BorderStyle)

    setborderStyle(Ptr(TextField1.Handle),BorderStyle.None)
    Just to remove the border, no need for enum :

    declare Sub setBorderStyle lib "UIKit" selector "setBorderStyle:" (id as ptr, style as integer)

    setborderStyle(Ptr(TextField1.Handle),0)

    OK, tried both but it doesn't seems to remove the border.

  14. Christoph D

    23 Dec 2014 Pre-Release Testers, Xojo Pro

    To be more exact. The second does not work. :)

  15. Michel B

    23 Dec 2014 Pre-Release Testers, Xojo Pro
    Edited 3 years ago

    @Christoph Dnbsp;Vocht OK, tried both but it doesn't seems to remove the border.

    @Christoph Dnbsp;Vocht To be more exact. The second does not work. :)

    :/

    borderstyle.xojo_binary_project

    Tested, works just fine here. Either form. Look in the TextField Open event.

  16. last week

    Aurelian N

    Dec 6 Pre-Release Testers, Xojo Pro

    Is there a way to change as well the color of the border ? I know that the subject is about no border but what about the border color if in case needs to be changed ? for example I need like a validation text field and if it`s empty to become red or something like that .

    Thanks

  17. Jérémie L

    Dec 6 Pre-Release Testers Europe (France)

    If you are using iOSKit from Jason King, you can add this function to a Module

    Public Sub setBorderColor(extends txt As iOSTextField, C As Color)
      
      
      Declare Function layer_ Lib UIKitLib selector "layer" (id As ptr) As Ptr
      Dim layer As ptr = layer_(bt.Handle)
      
      Dim uic As New UIColor(C)
      
      declare sub setBorderColor lib UIKitLib selector "setBorderColor:" (obj_id as ptr, col as ptr)
      setBorderColor(layer, uic.id)
    End Sub
  18. 7 days ago

    Aurelian N

    Dec 7 Pre-Release Testers, Xojo Pro

    @Jérémie Leroy Declare Function layer_ Lib UIKitLib selector "layer" (id As ptr) As Ptr
    Dim layer As ptr = layer_(bt.Handle)

    Dim uic As New UIColor(C)

    declare sub setBorderColor lib UIKitLib selector "setBorderColor:" (obj_id as ptr, col as ptr)
    setBorderColor(layer, uic.id )

    Hi Jérémie,

    I get an error when adding this method saying :

    line 2
    This item does not exist
    Dim layer As ptr = layer_(bt.Handle)

    Any idea why ?

    Thanks .

  19. Dave S

    Dec 7 San Diego, California USA

    shouldn't that be

    txt.handle
  20. Jérémie L

    Dec 7 Pre-Release Testers Europe (France)

    Yes it should be txt.handle
    I copy/pasted some code without checking all of it.

    The same function can be used to change the border color of a button.

  21. 4 days ago

    Aurelian N

    Dec 9 Pre-Release Testers, Xojo Pro

    Hi guys,

    Well I did created the module and added the code but still no changed in the interface .

    Here is how I end up enabling the color :

    tfFullName.setBorderColor(ColorModule.Red)

    but still the color stays the same gray that it is on the original control.

    Any ideas ? thanks .

or Sign Up to reply!