iphone ios7 segmented UISegmentedControl change only border color

后端 未结 6 1877
陌清茗
陌清茗 2020-12-29 13:47

Been looking around and trying to change just the border color (with a different text color) with no luck. Can change the tint, but changes both the text and border.

6条回答
  •  天涯浪人
    2020-12-29 14:32

    What worked for me: is as other answers suggest, change the tintColor of the segmentedControl to clearColor. And manually tint the images to your app tint color.

    Remember to use the imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal on the tinted image

    -(UIImage *)tintedImage:(UIImage *)image withColor:(UIColor *)tintColor
    {
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGRect rect = (CGRect){ CGPointZero, image.size };
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    [image drawInRect:rect];
    
    CGContextSetBlendMode(context, kCGBlendModeSourceIn);
    [tintColor setFill];
    CGContextFillRect(context, rect);
    
    UIImage *newImage  = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    

提交回复
热议问题