开发者

How to customize the UISegmentedControl in iOS?

开发者 https://www.devze.com 2023-03-28 11:18 出处:网络
I am customizing the U开发者_高级运维ISegmentedControl, but I got a problem. How to apply background image in the UISegmentedControl ? Changing the tint color does not fulfill my requirements.

I am customizing the U开发者_高级运维ISegmentedControl, but I got a problem.

How to apply background image in the UISegmentedControl ? Changing the tint color does not fulfill my requirements.

Thanks


////Segmented Controll
NSArray *segmentTextContent = [NSArray arrayWithObjects: @"First",@"Second",@"Third",@"Forth", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);

[segmentedControl addTarget:self action:@selector(segmentAction) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.enabled = true;
segmentedControl.selectedSegmentIndex = 0;

// cutomize the font size inside segmentedControl
for (id segment in [segmentedControl subviews]) 
{
    for (id label in [segment subviews]) 
    {
        if ([label isKindOfClass:[UILabel class]])
        {
            [label setTextAlignment:UITextAlignmentCenter];
            [label setFont:[UIFont boldSystemFontOfSize:11]];
            //[label setTextColor:[UIColor greenColor]];
        }
    }           
}


You could try http://idevrecipes.com/2010/12/11/custom-segmented-controls/.

0

精彩评论

暂无评论...
验证码 换一张
取 消