ios怎么自定义滑杆效果
发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,本篇内容介绍了"ios怎么自定义滑杆效果"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!先让我们看看效
千家信息网最后更新 2025年11月09日ios怎么自定义滑杆效果
本篇内容介绍了"ios怎么自定义滑杆效果"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
先让我们看看效果:
主要实现的代码:
UIImage *thumbWithLevel(float aLevel){ float INSET_AMT = 1.5f; CGRect baseRect = CGRectMake(0, 0, 40, 100); CGRect thumbRect = CGRectMake(0, 40, 40, 20); UIGraphicsBeginImageContext(baseRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor darkGrayColor] setFill]; CGContextAddRect(context, CGRectInset(thumbRect, INSET_AMT, INSET_AMT)); CGContextFillPath(context); [[UIColor whiteColor] setStroke]; CGContextSetLineWidth(context, 2); CGContextAddRect(context, CGRectInset(thumbRect, 2 * INSET_AMT, 2 * INSET_AMT)); CGRect ellipseRect = CGRectMake(0, 0, 40, 40); [[UIColor colorWithWhite:aLevel alpha:1] setFill]; CGContextAddEllipseInRect(context, ellipseRect); CGContextFillPath(context); NSString *numString = [NSString stringWithFormat:@"%0.2f",aLevel]; UIColor *textColor = (aLevel > 0.5) ? [UIColor blackColor] : [UIColor whiteColor]; UIFont *font = [UIFont fontWithName:@"Georgia" size:15]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.lineBreakMode = NSLineBreakByCharWrapping; style.alignment = NSTextAlignmentCenter; NSDictionary *attr = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:style,NSForegroundColorAttributeName:textColor}; [numString drawInRect:CGRectInset(ellipseRect, 0, 6) withAttributes:attr]; [[UIColor grayColor] setStroke]; CGContextSetLineWidth(context, 3); CGContextAddEllipseInRect(context, CGRectInset(ellipseRect, 2, 2)); CGContextStrokePath(context); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage;}在这里我们通过context的方法将图片画出了,对于性能有点要求,但是现在应该不在乎这点性能了
- (void)updateThumb{ if ((self.value < 0.98) && (ABS(self.value - previousValue) < 0.1f)) { return; } UIImage *customImg = thumbWithLevel(self.value); [self setThumbImage:customImg forState:UIControlStateHighlighted]; previousValue = self.value;}通过滑块的值来使上面的值进行变化,更加的直观
[self setThumbImage:simpleThumb() forState:UIControlStateNormal]; [self addTarget:self action:@selector(startDrag:) forControlEvents:UIControlEventTouchDown]; [self addTarget:self action:@selector(updateThumb) forControlEvents:UIControlEventValueChanged]; [self addTarget:self action:@selector(endDrag:) forControlEvents:UIControlEventTouchUpOutside | UIControlEventTouchUpInside];
"ios怎么自定义滑杆效果"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
效果
滑杆
内容
性能
更多
知识
实用
直观
学有所成
接下来
代码
困境
图片
实际
情况
文章
方法
来使
案例
编带
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
淘宝数据库营销
美点互联网科技
研究生学 网络安全 天赋
分布式数据库国外研究情况
网络技术的做法
大型系统软件开发完工百分比
数据库开发试题及答案
显示器和服务器连接不上
edb数据库无法打开
苏州软件开发培训的机构
数据库中创建默认日期
java开发用什么数据库
服务器按什么键设置u盘
网络安全观后感200字初二作文
苏州江苏高性能服务器出售
数据库栈是什么
ipv6 的服务器
网络安全具备的特征包括
网络安全与数据分离
网络安全性建设
网牛数据云服务器
分期乐逾期上报金融数据库严重吗
全国联销图数据库
深圳南湾区服务器
网络技术综合实习
天龙八部荣耀版怎么删除服务器
日本官方的专利数据库
世界银行企业数据库
中国人口数据库
佛山软件开发好吗