¡@

Home 

2014/10/15 ¤U¤È 10:07:39

iphone Programming Glossary: drawrect

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

changing the color value continuously. Follow up I would put the code to do this in my ImageView's drawRect method right As always a code snippet would greatly aid in my understanding as opposed to a link. Update.. other images setting the image in IB and calling setNeedsDisplay in my view controller. Update drawRect is not being called. Final update I found an old project that had an imageView set up properly so I.. 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..

Placeholder in UITextView

http://stackoverflow.com/questions/1328638/placeholder-in-uitextview

999 setAlpha 0 void setText NSString text super setText text self textChanged nil void drawRect CGRect rect if self placeholder length 0 if _placeHolderLabel nil _placeHolderLabel UILabel alloc..

Tricks for improving iPhone UITableView scrolling performance?

http://stackoverflow.com/questions/1352479/tricks-for-improving-iphone-uitableview-scrolling-performance

the inactive entries when you receive a memory warning Draw everything in the UITableViewCell 's drawRect if possible avoid subviews at all costs or if you require the standard accessibility functionality the.. at all costs or if you require the standard accessibility functionality the content view's drawRect Make your UITableViewCell 's layer opaque same goes for the content view if you have one Use the reusableCellIdentifier..

iPhone - UILabel containing text with multiple fonts at the same time

http://stackoverflow.com/questions/1417346/iphone-uilabel-containing-text-with-multiple-fonts-at-the-same-time

forWidth lineBreakMode Alternatively you can subclass UILabel and draw the text yourself in drawRect. If you do it this way just add an instance variable to tell you how much of the string to draw in one..

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.. 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.. ctx self.bounds.size.width self.bounds.size.height 1 CGContextStrokePath ctx super drawRect rect UPD As of iOS 6 Apple added NSAttributedString support for UILabel so now it's much easier and..

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

initWithFrame CGRect frame if self super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c..

Inner shadow effect on UIView layer?

http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer

effect to it but I am not quite sure how to do this. I suppose I would be required to draw in drawRect however this would add the layer on top of other UIView objects since it's supposed to be a bar behind.. using 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..

Custom UINavigationBar Background

http://stackoverflow.com/questions/704558/custom-uinavigationbar-background

as per the example iphone objective c share improve this question You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage.. You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage imageNamed @ NavigationBar.png image drawInRect CGRectMake 0 0 self.frame.size.width..

How do I draw a line on the iPhone?

http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone

and under Class Identity click the dropdown and 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.. 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..

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

where whites would be replaced with tint I will be changing the color value continuously. Follow up I would put the code to do this in my ImageView's drawRect method right As always a code snippet would greatly aid in my understanding as opposed to a link. Update Subclassing a UIImageView with the code Ramin suggested... see the image but it is not being tinted. I also tried loading other images setting the image in IB and calling setNeedsDisplay in my view controller. Update drawRect is not being called. Final update I found an old project that had an imageView set up properly so I could test Ramin's code and it works like a charm Final final.. Final final update For those of you just 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..

Placeholder in UITextView

http://stackoverflow.com/questions/1328638/placeholder-in-uitextview

text length 0 self viewWithTag 999 setAlpha 1 else self viewWithTag 999 setAlpha 0 void setText NSString text super setText text self textChanged nil void drawRect CGRect rect if self placeholder length 0 if _placeHolderLabel nil _placeHolderLabel UILabel alloc initWithFrame CGRectMake 8 8 self.bounds.size.width 16 0 _placeHolderLabel.lineBreakMode..

Tricks for improving iPhone UITableView scrolling performance?

http://stackoverflow.com/questions/1352479/tricks-for-improving-iphone-uitableview-scrolling-performance

cache for the images used in the table and invalidate all the inactive entries when you receive a memory warning Draw everything in the UITableViewCell 's drawRect if possible avoid subviews at all costs or if you require the standard accessibility functionality the content view's drawRect Make your UITableViewCell 's layer.. in the UITableViewCell 's drawRect if possible avoid subviews at all costs or if you require the standard accessibility functionality the content view's drawRect Make your UITableViewCell 's layer opaque same goes for the content view if you have one Use the reusableCellIdentifier functionality as recommended by the UITableView..

iPhone - UILabel containing text with multiple fonts at the same time

http://stackoverflow.com/questions/1417346/iphone-uilabel-containing-text-with-multiple-fonts-at-the-same-time

where the first one's text ends. You can get that via sizeWithFont forWidth lineBreakMode Alternatively you can subclass UILabel and draw the text yourself in drawRect. If you do it this way just add an instance variable to tell you how much of the string to draw in one format and draw the rest in another. share improve this..

underline text in UIlabel

http://stackoverflow.com/questions/2711297/underline-text-in-uilabel

right justfied I am new here so thank in advance. iphone 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.. new here so thank in advance. iphone 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 0 self.bounds.size.height 1 CGContextAddLineToPoint ctx self.bounds.size.width self.bounds.size.height 1 CGContextStrokePath ctx super drawRect rect UPD As of iOS 6 Apple added NSAttributedString support for UILabel so now it's much easier and works for multiple lines NSDictionary underlineAttribute @ NSUnderlineStyleAttributeName..

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

borderColor fillColor position BOOL isOpaque return 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..

Inner shadow effect on UIView layer?

http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer

gradient atIndex 0 I'd like to add an inner shadow effect to it but I am not quite sure how to do this. I suppose I would be required to draw in drawRect however this would add the layer on top of other UIView objects since it's supposed to be a bar behind some buttons so I am at a loss as to what to do I could add.. For anyone else wondering how to draw an inner shadow using 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..

Custom UINavigationBar Background

http://stackoverflow.com/questions/704558/custom-uinavigationbar-background

template so it is not done in my root controller as per the example iphone objective c share improve this question You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage imageNamed @ NavigationBar.png image drawInRect CGRectMake.. the example iphone objective c share improve this question You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage imageNamed @ NavigationBar.png image drawInRect CGRectMake 0 0 self.frame.size.width self.frame.size.height @end 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

new View selected hit Cmd 4 to bring up the Identity Inspector and under Class Identity click the dropdown and 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.. Identity click the dropdown and 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..

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

with tint I will be changing the color value continuously. Follow up I would put the code to do this in my ImageView's drawRect method right As always a code snippet would greatly aid in my understanding as opposed to a link. Update Subclassing a UIImageView.. I also tried loading other images setting the image in IB and calling setNeedsDisplay in my view controller. Update drawRect is not being called. Final update I found an old project that had an imageView set up properly so I could test Ramin's code.. just 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..

Placeholder in UITextView

http://stackoverflow.com/questions/1328638/placeholder-in-uitextview

1 else self viewWithTag 999 setAlpha 0 void setText NSString text super setText text self textChanged nil void drawRect CGRect rect if self placeholder length 0 if _placeHolderLabel nil _placeHolderLabel UILabel alloc initWithFrame CGRectMake..

Tricks for improving iPhone UITableView scrolling performance?

http://stackoverflow.com/questions/1352479/tricks-for-improving-iphone-uitableview-scrolling-performance

and invalidate all the inactive entries when you receive a memory warning Draw everything in the UITableViewCell 's drawRect if possible avoid subviews at all costs or if you require the standard accessibility functionality the content view's drawRect.. if possible avoid subviews at all costs or if you require the standard accessibility functionality the content view's drawRect Make your UITableViewCell 's layer opaque same goes for the content view if you have one Use the reusableCellIdentifier..

iPhone - UILabel containing text with multiple fonts at the same time

http://stackoverflow.com/questions/1417346/iphone-uilabel-containing-text-with-multiple-fonts-at-the-same-time

get that via sizeWithFont forWidth lineBreakMode Alternatively you can subclass UILabel and draw the text yourself in drawRect. If you do it this way just add an instance variable to tell you how much of the string to draw in one format and draw the..

underline text in UIlabel

http://stackoverflow.com/questions/2711297/underline-text-in-uilabel

in advance. iphone 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.. 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.. 1 CGContextAddLineToPoint ctx self.bounds.size.width self.bounds.size.height 1 CGContextStrokePath ctx super drawRect rect UPD As of iOS 6 Apple added NSAttributedString support for UILabel so now it's much easier and works for multiple lines..

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

return 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..

Inner shadow effect on UIView layer?

http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer

to add an inner shadow effect to it but I am not quite sure how to do this. I suppose I would be required to draw in drawRect however this would add the layer on top of other UIView objects since it's supposed to be a bar behind some buttons so I.. draw an inner shadow using 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..

Custom UINavigationBar Background

http://stackoverflow.com/questions/704558/custom-uinavigationbar-background

in my root controller as per the example iphone objective c share improve this question You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage imageNamed @ NavigationBar.png.. improve this question You just have to overload drawRect like that @implementation UINavigationBar CustomImage void drawRect CGRect rect UIImage image UIImage imageNamed @ NavigationBar.png image drawInRect CGRectMake 0 0 self.frame.size.width self.frame.size.height..

How do I draw a line on the iPhone?

http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone

the Identity Inspector and under Class Identity click the dropdown and 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.. 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..

iPhone: why isn't drawRect getting called?

http://stackoverflow.com/questions/1053761/iphone-why-isnt-drawrect-getting-called

any retained subviews of the main view. e.g. self.myOutlet nil void dealloc super dealloc @end iphone quartz graphics drawrect share improve this question drawRect is a method for UIView subclasses. Try to subclass UIView and change the type of..

composite colors: CALayer and blend mode on iPhone

http://stackoverflow.com/questions/1658751/composite-colors-calayer-and-blend-mode-on-iphone

myContext 1.0 1.0 1.0 0.9 CGContextFillRect myContext UIScreen mainScreen .bounds @end And here is the main view drawrect code where I use my CALayer void drawRect CGRect rect get the drawing context CGContextRef myContext UIGraphicsGetCurrentContext..

How to draw an UIImage or directly in -drawRect:?

http://stackoverflow.com/questions/1663815/how-to-draw-an-uiimage-or-directly-in-drawrect

UISearchBar: Changing the appearance - Shape, Background, Overlay an Image

http://stackoverflow.com/questions/2370002/uisearchbar-changing-the-appearance-shape-background-overlay-an-image

iPhone app as seen below How would you overlay an image to produce this effect iphone customization uisearchbar drawrect share improve this question Upon some investigating of possibilites to customize the search bar I'm inclined to say..

How to fill a path with gradient in drawRect:?

http://stackoverflow.com/questions/2985359/how-to-fill-a-path-with-gradient-in-drawrect

the entire view that this is in with the gradient covering up my original path. iphone core graphics quartz graphics drawrect share improve this question I would clip to the path you want to fill and use CGContextDrawLinearGradient. Here is a..

iPhone CGContext: drawing two lines with two different colors

http://stackoverflow.com/questions/3041776/iphone-cgcontext-drawing-two-lines-with-two-different-colors

is my code I use in the drawRect method. I am trying to draw a red and a blue line void drawRect CGRect rect NSLog @ drawrect CGContextRef bluecontext UIGraphicsGetCurrentContext CGContextSetLineWidth bluecontext 2.0 CGContextSetStrokeColorWithColor..

subclassed UITableViewCell - backgroundView covers up anything I do in drawRect

http://stackoverflow.com/questions/3527925/subclassed-uitableviewcell-backgroundview-covers-up-anything-i-do-in-drawrect

set cell.background to use the background UIImageView cell.backgroundView bgImageView iphone uitableviewcell drawrect share improve this question You are not really supposed to mix the drawing with your cell like that you are operating..

what is the difference between UIImageView and drawInRect?

http://stackoverflow.com/questions/3838725/what-is-the-difference-between-uiimageview-and-drawinrect

one is efficient Or someother function is available better than this Thanks in advance.... iphone uiimageview uiimage drawrect share improve this question Using the drawInRect method has CoreGraphics draw the image into the active CGContext using..

Custom UITableViewCell and animation on setSelected:animated:

http://stackoverflow.com/questions/3982942/custom-uitableviewcell-and-animation-on-setselectedanimated

from selected to not selected it fades from invisible to not selected. What can cause this iphone uitableviewcell ios drawrect share improve this question A little late answer but might still be useful to you and others. What you need to do is..

Mysterious “progressive slowing” problem in run loop / drawRect

http://stackoverflow.com/questions/4786754/mysterious-progressive-slowing-problem-in-run-loop-drawrect

5334 1a03 time difference was 299 27 27.373 stepwiseDrawing 5334 1a03 time difference was 297 iphone cocoa ios drawrect share improve this question First let me say this was an interesting puzzle. I had a lot of fun working on this one...

UITableViewCell dynamic height :/

http://stackoverflow.com/questions/7281467/uitableviewcell-dynamic-height

trying stuff with frames en sizes but i can't get the perfect solution.. I do this in the UITableViewCell file in the drawrect method. self.tweet.lineBreakMode UILineBreakModeWordWrap self.tweet.numberOfLines 0 self.tweet.font UIFont fontWithName..

Any possible way to call drawRect from a UIViewcontroller class?

http://stackoverflow.com/questions/7624099/any-possible-way-to-call-drawrect-from-a-uiviewcontroller-class

let me know if there's any way to use drawRect in a UIViewController . Thanks iphone uiviewcontroller core graphics drawrect share improve this question A view controller naturally has a pointer to its view so of course you can call the view's..

Most efficient way to draw part of an image in iOS

http://stackoverflow.com/questions/8035673/most-efficient-way-to-draw-part-of-an-image-in-ios

UIImageView 's frame and clipToBounds produces better results with less flexibility . iphone ios uiimage quartz 2d drawrect share improve this question I guessed you are doing this to display part of an image on the screen because you mentioned..

How can I tint a UIImage with gradient?

http://stackoverflow.com/questions/8098130/how-can-i-tint-a-uiimage-with-gradient

UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext return gradientImage iphone uiimage core graphics drawrect tint share improve this question I believe that the following should work do comment if it doesn't Load image UIImage..

How to override -drawrect in UIButton subclass?

http://stackoverflow.com/questions/816024/how-to-override-drawrect-in-uibutton-subclass

to override drawrect in UIButton subclass HI. I need to write some text over a custom button. So I subclassed UIButton. In drawrect I write.. drawrect in UIButton subclass HI. I need to write some text over a custom button. So I subclassed UIButton. In drawrect I write the text I need. The problem is that the text ends up under the button. After I write my text UIButton's drawrect.. I write the text I need. The problem is that the text ends up under the button. After I write my text UIButton's drawrect goes ahead and draws on top of me. I am not even calling super drawrect rect even though I was anticipating calling it before..

How to draw rectangle?

http://stackoverflow.com/questions/8195095/how-to-draw-rectangle

0.0 0.0 1.0 CGContextSetRGBStrokeColor context 1.0 0.0 0.0 1.0 CGContextFillRect context rectangle iphone objective c drawrect share improve this question You can't do it in a viewController. You need to extend your View and add the code under..