iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在代码中使用tintColor绘制像UITabBar这样的渐变大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
认情况下,UITabBar绘制一个微妙的渐变:

我想用任何给定的TintColor在我的代码中复制这种外观和感觉.为了说清楚:我不想在UITabBar上设置TintColor(从iOS 5开始就可以),我想在我自己的UIView中绘制渐变.

我知道如何绘制渐变,我的问题是如何从TintColor派生渐变的颜色.我正在虑获得颜色的亮度并使用不同的亮度设置生成其他颜色,但这似乎不能很好地工作,并且看起来不像我希望它看起来那么好.

我需要我的开源TabBarController的代码https://github.com/NOUSguide/NGTabBarController

这是我当前创建渐变的代码

UIColor *baseColor = self.TintColor;
CGFloat hue,saturation,brightness,alpha;

// TODO: Only works on iOS 5
[baseColor getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];

// That's the question,how to compute the colors ...
NSArray *colors = [NSArray arrayWithObjects:
                   [UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.2 alpha:alpha],[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.15 alpha:alpha],[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.1 alpha:alpha],baseColor,nil];
NSUInteger colorsCount = colors.count;
CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors objectATindex:0] CGColor]);

NSArray *LOCATIOns = [NSArray arrayWithObjects:[NSnumber numberWithFloat:0.0],[NSnumber numberWithFloat:0.25],[NSnumber numberWithFloat:0.49],[NSnumber numberWithFloat:0.5],nil];
CGFloat *gradientLOCATIOns = NULL;
NSUInteger LOCATIOnsCount = LOCATIOns.count;

gradientLOCATIOns = (CGFloat *)malloc(sizeof(CGFloat) * LOCATIOnsCount);

for (NSUInteger i = 0; i < LOCATIOnsCount; i++) {
    gradientLOCATIOns[i] = [[LOCATIOns objectATindex:i] floatValue];
}

NSMutableArray *gradientColors = [[NSMutableArray alloc] initWithCapacity:colorsCount];
[colors enumerateObjectsUsingBlock:^(id object,NSUInteger index,BOOL *stop) {
    [gradientColors addObject:(id)[(UIColor *)object CGColor]];
}];

_gradientRef = CGGradientCreateWithColors(colorSpace,(__bridge CFArrayRef)gradientColors,gradientLOCATIOns);

if (gradientLOCATIOns) {
    free(gradientLOCATIOns);
}

解决方法

大佬总结

以上是大佬教程为你收集整理的ios – 在代码中使用tintColor绘制像UITabBar这样的渐变全部内容,希望文章能够帮你解决ios – 在代码中使用tintColor绘制像UITabBar这样的渐变所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。