Skip to content

Instantly share code, notes, and snippets.

@epatel
Created November 7, 2011 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epatel/1345686 to your computer and use it in GitHub Desktop.
Save epatel/1345686 to your computer and use it in GitHub Desktop.
Handy lines to set tint color of a UISlider (pre iOS5)
/* setting tint on slider */
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 7), NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(1, 0, 18, 7)
cornerRadius:3.0] addClip];
[[UIColor grayColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(9, 0, 20, 7)] fill];
[tintColor setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 5+5, 7)] fill];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(1, 1, 18, 7)
cornerRadius:3.0];
path.lineWidth = 3;
[[UIColor blackColor] set];
[path strokeWithBlendMode:kCGBlendModeNormal alpha:0.3];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
image = [image stretchableImageWithLeftCapWidth:8 topCapHeight:4];
[slider setMinimumTrackImage:image forState:UIControlStateNormal];
[slider setMaximumTrackImage:image forState:UIControlStateNormal];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment