Reputation: 167
In my Project i am using segment Controller .. they have four segment in my segment Controller ..My question is I want this background color and font color and State selected color and separator color[White when select the segment]
Like this Image
But My screen is
My code Is
- (void)viewDidLoad {
[self changeColor];
}
- (void)changeColor{
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:83.0f/255.0f green:198.0f/255.0f blue:255.0f/255.0f alpha:1.0]} forState:UIControlStateSelected];
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:197.0f/255.0f green:197.0f/255.0f blue:197.0f/255.0f alpha:1.0]} forState:UIControlStateNormal];
[mailboxsegment setTintColor:[UIColor colorWithRed:202.0f/255.0f green:202.0f/255.0f blue:202.0f/255.0f alpha:1.0]];
UIFont *font = [UIFont boldSystemFontOfSize:09.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[mailboxsegment setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
my code i will try to change background color and change font size
Upvotes: 1
Views: 1604
Reputation: 625
please try this one
- (void)segmentAction:(UISegmentedControl *)segment
{
UIColor *selectedColor = [UIColor whiteColor];
UIColor *deselectedColor = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0];
for (UIControl *subview in [segment subviews])
{
if ([subview isSelected])
[subview setTintColor:selectedColor];
else
[subview setTintColor:deselectedColor];
}
}
Upvotes: 2
Reputation: 2693
You can create your custom segmented control
. But its little complicated to create custom segmented control
as you will have to provide images
for selected
and deselected
states, 1px image
for separator
etc.
Instead of this i will suggest you to use four different buttons
and apply logic to select only one button
at a time.
To get effect of separator
color, place these four buttons
inside a stack view
or a normal UIView
and set background color of that container view to the color which you want to set for separator
.
Upvotes: 0