ios - 为 UISlider 设置 ThumbImage 含糊不清

标签 ios objective-c uislider

image

这是我设置 slider 的thumbImage

 [_slider setThumbImage:[UIImage getRoundImageWithColor:SharedColor.themeGreen size:CGSizeMake(20, 20)] forState:UIControlStateNormal];

这是绘制的 thumbImage。我是为了显示视频播放进度条
+ (UIImage *)getRoundImageWithColor:(UIColor*)color size:(CGSize)size{

CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);     
CGContextFillEllipseInRect(context, rect);

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

最佳答案

UIImage *image = [[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

或者
UIImage *image = [self imageWithColor:[UIColor redColor]];

在 slider 中设置图像。
[slider setThumbImage:[self imageWithImage:image scaledToSize:CGSizeMake(32, 59)] forState:UIControlStateNormal];

这是在 slider 中绘制的 thumbImage。
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

如果我们没有任何图像,则传递 UIColor 并创建图像。
- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 32.0f, 32.0f);
    UIGraphicsBeginImageContextWithOptions(rect.size, CGColorGetAlpha(color.CGColor) == 1.0f , 0.0f);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

关于ios - 为 UISlider 设置 ThumbImage 含糊不清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48423041/

相关文章:

javascript - 在 iOS 上使用 Chrome 不会触发图像 onLoad 事件

iphone - 如何让我的 iOS 应用程序支持 iPhone 5 上的 4 英寸显示屏

objective-c - 从 Objective-C 类调用 Swift 函数

ios - 更改 UISlider thumbImage 的大小

jQuery UI 多个带有金额的 slider

ios - UISlider 不调用辅助功能增量和减量

ios - 以编程方式添加导航栏 iOS

objective-c - DynamoDB - 项目未上传

ios - 用嵌套 block 保留 self ?

ios - 从 Web 服务 + AFnetworking 获取数据所需的时间?