If you take a look at the sample project linked below, you can see that I’ve got an iOSSegmentedControl that’s sat on top of a dark canvas.
Using iOSControl.SetTintColor, I can set the colour that’s used to draw the outline and selected item background to white. However, the text colour of the selected item also stays white, and white-on-white is a little hard to read
Does anyone know how I can modify the text colour of the selected item?
if you have access to BACKGROUND color then it, and TINTCOLOR are the only two colors that make a difference on a iOS SegmentedControl
the Selected segment will have a have a background of “tintcolor” and text of “background color”
while non selected segments will be the opposite… if that makes sense
// NOT XOJO CODE
let temp : UISegmentedControl = UISegmentedControl()
temp.frame=CGRectMake(61.0,113.0,200.0,28.0)
temp.backgroundColor=UIColor.redColor()
temp..tintColor=UIColor.orangeColor()
temp.insertSegmentWithTitle("Segment1", atIndex:0, animated:false)
temp.insertSegmentWithTitle("Segment2", atIndex:1, animated:false)
temp.selectedSegmentIndex=1
Ulrich: thanks for the transparency tip. It’s not ideal, but does at least make it possible to read the text.
Dave: we don’t have access to the backgroundColor property via Xojo, so this looks like something that can only be achieved via declares. I’ll look forward to Ulrich’s session on declares at the MBS conference in a couple of weeks’ time and put it to use sorting this out
I am afraid Ill have to disappoint you in that case. The documentation says nowhere that a standard buttonCell would be used; it really only gives access to images and text properties. While it still could be that Apple uses cells behind the stage, they did not open access to them. So the only way I see currently would be a custom control.
Of course! You could track down the view hierarchy and see if on UIResponder level one of the views is a textcell (or subytpe). Well, Tom, I dont know if Ill find time. Currently I dont have much more than the headlines for the session. But Ill see what I can do
It does look like you should be able to set background color even if it’s only via a declare
The inheritance tree suggests that should work
I just have no idea what Apple will do with that at run time
Should be no problem. A UISegmentedControl is still a UIControl is still a UIView is still a UIResponder so everything that works for these classes works for the lowest subclass too. And yes, its still a NSObject of course.
I havent found any documentation on the inner structure.
Tom, if youre feeling adventurous, you might start iOSLib and create a subclass of AppleControl. Name it like AppleSegmentedControl and copy a classptr from another class, make sure its name is not extended with a number and change the string literal in it to “UISegmentedControl”.
Create a Shared method MakeFromPtr (aPtr As Ptr) As AppleSegmentedControl with the code
Return if (aPtr = nil, Nil, New AppleSegmentedControl (aPtr))
That should be enough to create an iOSLib object you can attach to an iOSSegmentedControl:
Dim ASC As New AppleSegmentedcontrol (mySegmentedControl.handle)
whose structure you could examine in the debugger or maybe copy properties from the AppleView class like its SubView AppleArray property for further debugger examination which maybe could give access to single cells if such exist, or simply play with the AppleView properties like backgroundColor or its layer.
EDIT: Hey, that could fill a few minutes of the session: “How do I create my own controls?” Thanks!
Examine the subviews! The segmentedcontrol has an array of subviews (UISegment) that seems to be a spin-off of a normal UIView, starting with the rightmost. Each has two subviews again, one for the image, one for the text. Both no real subclasses of UIImageView or UITextField, but accessible as UIViews and the latter one accepts a setTextColor: too.
Should be no problem for Apple as long as you only use official UIView or available subclass features, I guess. But cannot guarantee
Sorry, Dave, correction:
The first subview of a UISegment is a standard UIImageView, and the second one is a UISegmentLabel which doesnt claim to inherit from anywhere but as the name suggests understands all the features of an UILabel.