Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用UIAppearance自定义后,SegmentControl的标题被扭曲_Objective C_Ios_Ios5_Custom Controls_Uisegmentedcontrol - Fatal编程技术网

Objective c 使用UIAppearance自定义后,SegmentControl的标题被扭曲

Objective c 使用UIAppearance自定义后,SegmentControl的标题被扭曲,objective-c,ios,ios5,custom-controls,uisegmentedcontrol,Objective C,Ios,Ios5,Custom Controls,Uisegmentedcontrol,自定义后,文本位置被扭曲 用于自定义的代码: + (void)customiseSegmentControl { UIImage *selectedImage = [[UIImage imageNamed:@"SegmentSelected.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:1]; UIImage *unselectedImage = [[UIImage imageNamed:@"

自定义后,文本位置被扭曲

用于自定义的代码:

+ (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];
}

检查此链接。。和代码

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]];
    }
 }           
}

谢谢你们的回答,伙计们。。解决了此问题。问题在于UIImage的UIEdgeInsets属性