iphone Programming Glossary: uigraphicsgetcurrentcontext
How do I make UILabel display outlined text? http://stackoverflow.com/questions/1103148/how-do-i-make-uilabel-display-outlined-text gc x pt.x 2 y str strlen str void drawRect CGRect rect CGContextRef theContext UIGraphicsGetCurrentContext CGRect viewBounds self.bounds CGContextTranslateCTM theContext 0 viewBounds.size.height CGContextScaleCTM.. CGRect rect CGSize shadowOffset self.shadowOffset UIColor textColor self.textColor CGContextRef c UIGraphicsGetCurrentContext CGContextSetLineWidth c 1 CGContextSetLineJoin c kCGLineJoinRound CGContextSetTextDrawingMode c kCGTextStroke..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed 0.5 green 0.5 blue 0 alpha 1.. with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage context self.frame self.image.CGImage..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context radians 90 else if orientation UIImageOrientationLeft..
How to take a screenshot programmatically http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically question UIGraphicsBeginImageContext self.window.bounds.size self.window.layer renderInContext UIGraphicsGetCurrentContext UIImage image UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext NSData data UIImagePNGRepresentation..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f 1.0f RGBA CGContextSetLineWidth..
How can i change the color of pagination dots of UIPageControl? http://stackoverflow.com/questions/2942636/how-can-i-change-the-color-of-pagination-dots-of-uipagecontrol recognizer self.currentPage void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetAllowsAntialiasing context true CGRect currentBounds self.bounds CGFloat dotsWidth self.numberOfPages..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor c borderColor CGColor..
How to capture UIView to UIImage without loss of quality on retina display http://stackoverflow.com/questions/4334233/how-to-capture-uiview-to-uiimage-without-loss-of-quality-on-retina-display imageWithView UIView view UIGraphicsBeginImageContext view.bounds.size view.layer renderInContext UIGraphicsGetCurrentContext UIImage img UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return img iphone uiimage.. UIGraphicsBeginImageContextWithOptions view.bounds.size view.opaque 0.0 view.layer renderInContext UIGraphicsGetCurrentContext UIImage img UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return img share improve..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path which will be the shape that gets..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview drawRect CGRect rect super drawRect rect Should I uncomment this int radius 5 CGContextRef context UIGraphicsGetCurrentContext CGContextBeginPath context CGContextAddArc context rect.origin.x radius rect.origin.y rect.size.height..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft CGContextScaleCTM context scaleRatio.. CGContextTranslateCTM context 0 height CGContextConcatCTM context transform CGContextDrawImage UIGraphicsGetCurrentContext CGRectMake 0 0 width height imgRef UIImage imageCopy UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext..
How do I draw a shadow under a UIView? http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview tried the following in a UIView subclass void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 CGContextRestoreGState.. about if you rearrange your code like this void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 super drawRect..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath c CGContextMoveToPoint..
How do I make UILabel display outlined text? http://stackoverflow.com/questions/1103148/how-do-i-make-uilabel-display-outlined-text gc CGContextSetTextDrawingMode gc kCGTextFillStroke CGContextShowTextAtPoint gc x pt.x 2 y str strlen str void drawRect CGRect rect CGContextRef theContext UIGraphicsGetCurrentContext CGRect viewBounds self.bounds CGContextTranslateCTM theContext 0 viewBounds.size.height CGContextScaleCTM theContext 1 1 CGContextSelectFont theContext Helvetica.. to do it by overriding drawTextInRect void drawTextInRect CGRect rect CGSize shadowOffset self.shadowOffset UIColor textColor self.textColor CGContextRef c UIGraphicsGetCurrentContext CGContextSetLineWidth c 1 CGContextSetLineJoin c kCGLineJoinRound CGContextSetTextDrawingMode c kCGTextStroke self.textColor UIColor whiteColor super drawTextInRect..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone learning about Core Graphics here is the simplest thing that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed 0.5 green 0.5 blue 0 alpha 1 .CGColor don't make color too saturated CGContextFillRect context.. it with a rectangle filled with the color you want along with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage context self.frame self.image.CGImage Blend mode could be any of CGBlendMode values. Now draw..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees double degrees return degrees M_PI 180 UIImage rotate UIImage src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context radians 90 else if orientation UIImageOrientationLeft CGContextRotateCTM context radians 90 else..
How to take a screenshot programmatically http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically into the saved photo library iphone share improve this question UIGraphicsBeginImageContext self.window.bounds.size self.window.layer renderInContext UIGraphicsGetCurrentContext UIImage image UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext NSData data UIImagePNGRepresentation image data writeToFile @ foo.png atomically..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel text uilabel underline share improve this question You may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f 1.0f RGBA CGContextSetLineWidth ctx 1.0f CGContextMoveToPoint ctx 0 self.bounds.size.height..
How can i change the color of pagination dots of UIPageControl? http://stackoverflow.com/questions/2942636/how-can-i-change-the-color-of-pagination-dots-of-uipagecontrol recognizer self.currentPage void swipedRight UISwipeGestureRecognizer recognizer self.currentPage void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetAllowsAntialiasing context true CGRect currentBounds self.bounds CGFloat dotsWidth self.numberOfPages kDotDiameter MAX 0 self.numberOfPages 1 kDotSpacer..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell NO id initWithFrame CGRect frame if self super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor c borderColor CGColor if position CustomCellBackgroundViewPositionTop CGContextFillRect..
How to capture UIView to UIImage without loss of quality on retina display http://stackoverflow.com/questions/4334233/how-to-capture-uiview-to-uiimage-without-loss-of-quality-on-retina-display devices. Does anybody know a solution for my issue UIImage imageWithView UIView view UIGraphicsBeginImageContext view.bounds.size view.layer renderInContext UIGraphicsGetCurrentContext UIImage img UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return img iphone uiimage scale retina display image capture share improve this..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer Core Graphics as per Costique suggestion then this is how on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path which will be the shape that gets the inner shadow In this case it's just a rounded rect but..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview problems implementing it. Here is my drawRect method void drawRect CGRect rect super drawRect rect Should I uncomment this int radius 5 CGContextRef context UIGraphicsGetCurrentContext CGContextBeginPath context CGContextAddArc context rect.origin.x radius rect.origin.y rect.size.height radius radius M_PI M_PI 2 1 CGContextAddArc context rect.origin.x..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app default NSException raise NSInternalInconsistencyException format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft CGContextScaleCTM context scaleRatio scaleRatio CGContextTranslateCTM context height 0 else CGContextScaleCTM.. height 0 else CGContextScaleCTM context scaleRatio scaleRatio CGContextTranslateCTM context 0 height CGContextConcatCTM context transform CGContextDrawImage UIGraphicsGetCurrentContext CGRectMake 0 0 width height imgRef UIImage imageCopy UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return imageCopy share improve this answer..
How do I draw a shadow under a UIView? http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview you want to apply shadows. Restore the graphics state I've tried the following in a UIView subclass void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 CGContextRestoreGState currentContext super drawRect rect ..but this doesn't.. superclass's drawRect to be 'wrapped' in a shadow then how about if you rearrange your code like this void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 super drawRect rect CGContextRestoreGState currentContext share improve..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone choose MyView. Next you need to implement the drawRect method in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath c CGContextMoveToPoint c 5.0f 5.0f CGContextAddLineToPoint c 50.0f 50.0f CGContextStrokePath..
How do I make UILabel display outlined text? http://stackoverflow.com/questions/1103148/how-do-i-make-uilabel-display-outlined-text CGContextShowTextAtPoint gc x pt.x 2 y str strlen str void drawRect CGRect rect CGContextRef theContext UIGraphicsGetCurrentContext CGRect viewBounds self.bounds CGContextTranslateCTM theContext 0 viewBounds.size.height CGContextScaleCTM theContext 1 1.. void drawTextInRect CGRect rect CGSize shadowOffset self.shadowOffset UIColor textColor self.textColor CGContextRef c UIGraphicsGetCurrentContext CGContextSetLineWidth c 1 CGContextSetLineJoin c kCGLineJoinRound CGContextSetTextDrawingMode c kCGTextStroke self.textColor..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone the simplest thing that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed 0.5 green 0.5 blue 0 alpha 1 .CGColor don't make.. color you want along with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage context self.frame self.image.CGImage Blend mode could..
blend two uiimages http://stackoverflow.com/questions/1309757/blend-two-uiimages with lines on it. I am trying to do it this way. UIGraphicsBeginImageContext CGSizeMake 320 480 CGContextRef context UIGraphicsGetCurrentContext create rect that fills screen CGRect bounds CGRectMake 0 0 320 480 This is my bkgnd image CGContextDrawImage context bounds..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees UIImage rotate UIImage src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context radians 90 else if orientation UIImageOrientationLeft..
How to take a screenshot programmatically http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically share improve this question UIGraphicsBeginImageContext self.window.bounds.size self.window.layer renderInContext UIGraphicsGetCurrentContext UIImage image UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext NSData data UIImagePNGRepresentation image..
How Do I Take a Screen Shot of a UIView? http://stackoverflow.com/questions/2214957/how-do-i-take-a-screen-shot-of-a-uiview I tried this code but all I get is a blank image. UIGraphicsBeginImageContext CGSizeMake 320 480 CGContextRef context UIGraphicsGetCurrentContext myUIView.layer drawInContext context UIImage screenShot UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel this question You may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f 1.0f RGBA CGContextSetLineWidth ctx 1.0f CGContextMoveToPoint..
How can i change the color of pagination dots of UIPageControl? http://stackoverflow.com/questions/2942636/how-can-i-change-the-color-of-pagination-dots-of-uipagecontrol void swipedRight UISwipeGestureRecognizer recognizer self.currentPage void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetAllowsAntialiasing context true CGRect currentBounds self.bounds CGFloat dotsWidth self.numberOfPages kDotDiameter..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell self super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor c borderColor CGColor if position CustomCellBackgroundViewPositionTop..
How to capture UIView to UIImage without loss of quality on retina display http://stackoverflow.com/questions/4334233/how-to-capture-uiview-to-uiimage-without-loss-of-quality-on-retina-display for my issue UIImage imageWithView UIView view UIGraphicsBeginImageContext view.bounds.size view.layer renderInContext UIGraphicsGetCurrentContext UIImage img UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return img iphone uiimage scale retina..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer then this is how on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path which will be the shape that gets the inner shadow In..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview method void drawRect CGRect rect super drawRect rect Should I uncomment this int radius 5 CGContextRef context UIGraphicsGetCurrentContext CGContextBeginPath context CGContextAddArc context rect.origin.x radius rect.origin.y rect.size.height radius radius M_PI..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft CGContextScaleCTM context scaleRatio scaleRatio CGContextTranslateCTM.. scaleRatio scaleRatio CGContextTranslateCTM context 0 height CGContextConcatCTM context transform CGContextDrawImage UIGraphicsGetCurrentContext CGRectMake 0 0 width height imgRef UIImage imageCopy UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext..
How do I draw a shadow under a UIView? http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview the graphics state I've tried the following in a UIView subclass void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 CGContextRestoreGState currentContext.. in a shadow then how about if you rearrange your code like this void drawRect CGRect rect CGContextRef currentContext UIGraphicsGetCurrentContext CGContextSaveGState currentContext CGContextSetShadow currentContext CGSizeMake 15 20 5 super drawRect rect CGContextRestoreGState..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone the drawRect method in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath c CGContextMoveToPoint c 5.0f 5.0f CGContextAddLineToPoint..
|