1

カスタマイズしたら文字位置がずれてしまった..

ここに画像の説明を入力

カスタマイズに使用されるコード:

+ (void)customiseSegmentControl {
UIImage *selectedImage = [[UIImage imageNamed:@"SegmentSelected.png"]
                    stretchableImageWithLeftCapWidth:5 topCapHeight:1];
UIImage *unselectedImage = [[UIImage imageNamed:@"SegmentUnselected.png"]
                    stretchableImageWithLeftCapWidth:5 topCapHeight:1];

[[UISegmentedControl appearance] setBackgroundImage:selectedImage forState:(UIControlStateSelected|UIControlStateHighlighted) barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:unselectedImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
4

1 に答える 1

0

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

このリンクを確認してください..とコード

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]];
    }
 }           
}
于 2012-08-19T05:15:35.090 に答える