In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to customize the slider effect of ios". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, let's see the effect:
The code of the main implementation:
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;}
Here we draw the picture through the method of context, which requires a little bit of performance, but we should not care about it now.
-(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;}
It is more intuitive to change the above value through the value of the slider.
[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]; and "how to customize the slider effect in ios" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.