drawrect

drawRect drawing 'transparent' text?

你说的曾经没有我的故事 提交于 2019-11-27 00:39:39
问题 I am looking to draw a UILabel (preferable through subclassing) as a transparent label, but with solid background. I draw up an quick example (sorry, it's ugly, but it gets the points across :)). Basically I have a UILabel and I would like the background to be a set colour, and the text should be transparent. I do not want to colour the text with the views background, but instead have it be 100% transparent, since I have a texture in the background that I want to make sure lines up inside and

Draw text along circular path in Swift for iOS

点点圈 提交于 2019-11-27 00:03:30
I am looking for some up to date help/hints on how to draw simple single line strings around the edge of a circle using Swift2 for iOS9 . I see quite dated examples involving old ObjC fragments, and oft limited to OS X only. Is this even possible in iOS within a custom UIView subclass's drawRect() method? I was going to say "What have you tried?", but it's Friday afternoon and I got off work early, so I took the opportunity to translate my old ObjC code. Here it is, suitable for Playground. It should be trivial to put it in your UIView. Swift 2 See below for Swift 3 & Swift 4 updates... import

UIView with shadow, rounded corners and custom drawRect

烂漫一生 提交于 2019-11-26 22:31:30
问题 I have to create a custom UIView that will have round corners, a border, a shadow and its drawRect() method is overridden to provide custom drawing code with which several straight lines are drawn into the view (I need to use a fast, lightweight approach here since many of these views may be rendered). The problem I'm currently facing is that the shadow doesn't apply anymore to the round corners as soon as I override drawRect() in the view class (even without any custom code yet in it). See

How can I tint a UIImage with gradient?

和自甴很熟 提交于 2019-11-26 19:09:13
问题 I searched everywhere but didn't find the solution. I have image 1. How can I programatically tint them with gradient to get images 2 and 3? Here are those images: Tints that I applied to them via Photoshop are simple 2-color linear gradients. And my question is: how can I achieve this effect programatically? Solution: jrtc27 gave me almost working example. I fixed it (for ARC) and made it reusable (using UIImage's category). Here is it: - (UIImage *)tintedWithLinearGradientColors:(NSArray *

Most efficient way to draw part of an image in iOS

被刻印的时光 ゝ 提交于 2019-11-26 18:47:02
问题 Given an UIImage and a CGRect , what is the most efficient way (in memory and time) to draw the part of the image corresponding to the CGRect (without scaling)? For reference, this is how I currently do it: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect frameRect = CGRectMake(frameOrigin.x + rect.origin.x, frameOrigin.y + rect.origin.y, rect.size.width, rect.size.height); CGImageRef imageRef = CGImageCreateWithImageInRect(image_.CGImage, frameRect

Make 2 contradictory methods work in drawRect

a 夏天 提交于 2019-11-26 17:17:21
问题 I'm writing an app building elements consisting of CGPoints. I have 2 buttons: makeRectangle and makeTriangle . For building/drawing stage I use three methods for rectangle and three methods for triangle inside drawRect . I'm stuck with my code in drawRect . In if-else-statement each method swaps the building/drawing scheme for previous element every time a button pressed. If I already have built rectangle and then I click makeTriangle button, I get new triangle but my rectangle turns into

subclassed UITableViewCell - backgroundView covers up anything I do in drawRect

我是研究僧i 提交于 2019-11-26 16:55:45
问题 I'm trying to make a subclassed UITableViewCell where I draw an image in the upper right corner. I have it working perfectly - except when I set self.backgroundView, my background image covers up the image drawn in drawRect. There must be a way to be able to set a background image (and the selectedBackgroundView) without covering up what's being done in drawRect. Am I going about this the wrong way? EDIT: I've posted an example project with the problem. - (id)initWithStyle:

Draw text along circular path in Swift for iOS

只谈情不闲聊 提交于 2019-11-26 09:06:49
问题 I am looking for some up to date help/hints on how to draw simple single line strings around the edge of a circle using Swift2 for iOS9 . I see quite dated examples involving old ObjC fragments, and oft limited to OS X only. Is this even possible in iOS within a custom UIView subclass\'s drawRect() method? 回答1: I was going to say "What have you tried?", but it's Friday afternoon and I got off work early, so I took the opportunity to translate my old ObjC code. Here it is, suitable for