ios怎么自定义滑杆效果
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇内容介绍了"ios怎么自定义滑杆效果"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!先让我们看看效
千家信息网最后更新 2026年11月02日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安全错误
数据库的锁怎样保障安全
云南咖啡
互联网科技产业
互联网科技财经
有马互联网科技
为想互联网科技
互联网科技作文
银优互联网科技有限公司
奔汉互联网科技
互联网科技汛
卓越科技互联网 招聘
互联网科技公司招聘
互联网和黑科技的看法
上海宁丞科技互联网
河南猎农互联网科技有限公司
黑科技 体验场景 互联网大会
互联网第三次科技革命特征
深圳互联网科技的发展
图游互联网科技
互联网科技手抄报图片
唐山双旺合互联网科技产业园
科技企业和互联网企业
互联网 科技
美国互联网科技
互联网科技小额贷款
互联网系的金融科技公司
湖北码尼互联网科技有限公司电话
银川新华互联网科技学校联系电话
互联网科技的全部知识
北京市互联网新科技
宇信科技在杭州互联网排第几