Any way to disable the border for iOSTextField ?
Should be fairly simple. TextView in XCode does not have any border. I looked at the class reference, though, and could not locate the property.
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) }
}
Maybe Jim can take a peek at this?
Anyone can make this working? Changing the color should do the job.
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
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.
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.
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 !
[quote=154487:@Michel Bujardet]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 ![/quote]
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.
The property to set is borderStyle. In Swift it is only one integer :
[code]The border style used by the text field.
Declaration
SWIFT
var borderStyle: UITextBorderStyle[/code]
That said, a borderless TextField will be challenging for the user to find if it is the same color as the background.
Thanks to Urlich Bogun’s UITextField project :
Public Enum BorderStyle
None
Line
Bezel
RoundedRect
[code] declare Sub setBorderStyle lib “UIKit” selector “setBorderStyle:” (id as ptr, style as BorderStyle)
setborderStyle(Ptr(TextField1.Handle),BorderStyle.None)[/code]
Just to remove the border, no need for enum :
[code] declare Sub setBorderStyle lib “UIKit” selector “setBorderStyle:” (id as ptr, style as integer)
setborderStyle(Ptr(TextField1.Handle),0) [/code]
[quote=154509:@Michel Bujardet]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) [/quote]
OK, tried both but it doesn’t seems to remove the border.
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.
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
If you are using iOSKit from Jason King, you can add this function to a Module
[code]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©
declare sub setBorderColor lib UIKitLib selector “setBorderColor:” (obj_id as ptr, col as ptr)
setBorderColor(layer, uic.id)
End Sub
[/code]
[quote=363239:@JrmieLeroy]Declare Function layer_ Lib UIKitLib selector “layer” (id As ptr) As Ptr
Dim layer As ptr = layer_(bt.Handle)
Dim uic As New UIColor©
declare sub setBorderColor lib UIKitLib selector “setBorderColor:” (obj_id as ptr, col as ptr)
setBorderColor(layer, uic.id)[/quote]
Hi Jrmie,
I get an error when adding this method saying : [quote]line 2
This item does not exist
Dim layer As ptr = layer_(bt.Handle)[/quote]
Any idea why ?
Thanks .
shouldn’t that be
txt.handle