Monday, April 25, 2011

Segmentcontrol Color on load?

Hi PPL :)

I am having some trouble with my segmentcontrol bar. I am trying to make it a gray/black color with this:

segmentControl3.tintColor = [UIColor colorWithRed:0.60 green:0.60 blue:0.60 alpha:1.0];

Under my getSegment action, and that works just fine when I click it. But my problem is that the load color is the standart blue one, and I can't seem to change that anywhere... I have tried to place it under viewDidLoad, but that diden't seen to work. I have read trough the UICatalog example, but in there all is declared in code. Is that the only way to get it right?

Thanks

From stackoverflow
  • You should be able to use tintColor to change the color of your control; try placing it in viewWillAppear:. Also make sure that your outlet is properly set. I use this in several applications.

    You can use [UIColor colorWithWhite: 0.6 alpha: 1.0] to save a little code

    CC : I have tried both the viewDidLoad method and viewWillAppear but it doesn't change colour until i click one of the segments for some reason :S Any other ideas?
    CC : Is it possible to run a IBAction on load?
    Ben Gottlieb : I would try pulling this code out and sticking it in its own test project; given that this should work as you've described, it's likely that there's something else at play here, and isolating this shoudl help track it down.
    CC : Thanks.. I'll try that later today to see if I can get it up and running... But if you have some code examples from your viewWillApper method, where you use the function I would be happy to see it.. thanks again :)
    CC : Hmm.. still not working for me.. My code looks like this in the IBAction method:
    CC : - (IBAction)getSegment:(id)sender{ UISegmentedControl *segmentControl = (UISegmentedControl *)sender; NSInteger segment =segmentControl.selectedSegmentIndex; segmentControl.tintColor = [UIColor colorWithRed:0.60 green:0.60 blue:0.60 alpha:1.0]; But can't seem to implement this anywhere else :S
    CC : Is it bacause the object segmentcontrol is first defined when valueChanged? How do I implement this while still using Interface Builder?
    CC : This really frustrates me.. Any help will be greatly appreciated.. When I refer to the object segmentControl3.tintColor = [UIColor colorWithRed:0.60 green:0.60 blue:0.60 alpha:1.0]; it says that the object is undeclared..
  • I made the mistake that I referred to the Segmented Control by pointer type and not by an outlet.. Everything is working fine now :) Thanks for all your help, just didn't understand it until now :D

0 comments:

Post a Comment