iphone ios7分段UISegmentedControl仅改变边框颜色 [英] iphone ios7 segmented UISegmentedControl change only border color

查看:95
本文介绍了iphone ios7分段UISegmentedControl仅改变边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环顾四周,试图改变边框颜色(使用不同的文字颜色),没有运气。可以更改色调,但同时更改文本和边框。

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.

推荐答案

您可以使用UIAppearance代理设置标题文本属性但保留tintColor为边框。
类似于:

You can use UIAppearance proxy to set title text attributes but preserve tintColor for borders. Something like:

 [[UISegmentedControl appearance] setTitleTextAttributes:@{ 
    NSForegroundColorAttributeName : [UIColor redColor] 
 } forState:UIControlStateNormal];

修改:

要着色图像,你可以在UImage的类别中使用类似的东西:

To tint images, you can use something like this in category on UImage:

- (instancetype)tintedImageWithColor:(UIColor *)tintColor {
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGRect rect = (CGRect){ CGPointZero, self.size };
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    [self drawInRect:rect];

    CGContextSetBlendMode(context, kCGBlendModeSourceIn);
    [tintColor setFill];
    CGContextFillRect(context, rect);

    UIImage *image  = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

这篇关于iphone ios7分段UISegmentedControl仅改变边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆