2013-11-24 5 views
2

iOS7에서 내 세그먼트 컨트롤의 테두리 색을 변경하는 데 문제가 있습니다. stackoverflow 다른 곳에서 다음 제안을 발견했습니다 :uisegmentedcontrol의 테두리 색

[[UISegmentedControl appearance] setTitleTextAttributes:@{ 
                  UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
                  UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0], 
                  UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0], 
                  NSForegroundColorAttributeName : [UIColor redColor], 

                  } forState:UIControlStateSelected]; 

    [self.segmentedControl setTitleTextAttributes:@{ 
                UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
                UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0], 
                UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0], 
                NSForegroundColorAttributeName : [UIColor redColor], 

                } forState:UIControlStateNormal]; 

두 경우 모두 내 테두리는 여전히 파란색입니다. settitleTextAttributes를 통해 글꼴 그림자, 테두리 색 또는 다른 것을 변경할 수 없습니다.

테두리 색은 어떻게 조정합니까?

답변

1

나는 이걸 너무 많이 고심했다. 그래서 나는 주변에서 일을했다. 나는 새로운 UILabel을 생성하고 하위 뷰로 분할 된 컨트롤러의 각 항목에 추가했습니다.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { 
    NSArray * segments = @[@"Crop",@"Nutrient",@"Product Group"]; 

    [self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"background-yellowgradient.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

    [self.segmentedControl setSegmentedControlStyle:UISegmentedControlStyleBar]; 
    for (int i=0; i<[self.segmentedControl.subviews count]; i++) 
    { 

     [[self.segmentedControl.subviews objectAtIndex:i] setTintColor:[UIColor clearColor]]; 
     UILabel *l = [[UILabel alloc] init]; 
     l.text = [segments objectAtIndex:i]; 
     l.textColor = [UIColor whiteColor]; 
     l.textAlignment = NSTextAlignmentCenter; 
     l.adjustsFontSizeToFitWidth = NO; 
     l.font = [UIFont systemFontOfSize:12]; 


     CGRect f = [[self.segmentedControl.subviews objectAtIndex:0] frame]; 
     f.size.width = self.segmentedControl.frame.size.width/3; 
     f.size.height = self.segmentedControl.frame.size.height; 
     f.origin.x = 0; 
     f.origin.y = 0; 

     l.frame = f; 

     [[[self.segmentedControl subviews] objectAtIndex:i] addSubview:l]; 

    } 
} 
else{ 
    // if it's not IOS7, then do what i was doing before for ios6.1 and below 
} 
2
[segmentControlObj setTintColor:[UIColor redColor]];