drawrect

Subclassing UIToolbar and overriding drawRect: - UIBarButtonItems NOT displaying

ぃ、小莉子 提交于 2019-12-13 03:09:01
问题 Context I'm using the 'initWithNavigationBarClass' method to initialize a UINavigationController with a custom toolbar, here is the line where I alloc init the UINavigationController navigationController = [[UINavigationController alloc] initWithNavigationBarClass:nil toolbarClass:[QuestionToolbar class]]; Is the class, "QuestionToolbar", I subclass UIToolbar and override drawrect, here is the drawRect method: - (void)drawRect:(CGRect)rect { [super drawRect:rect]; UIImage *backgroundImage =

iPhone - setNeedsDisplay doesn't call drawRect

柔情痞子 提交于 2019-12-13 01:27:31
问题 I have seen many posts about this problem but didn't get an answer. I have a controller which view is added to the main window. The controller's view has a subview which has a drawRect. The problem is that this function is never called even if I call [self setNeedsDisplay]. Thanks 回答1: It is -(void)drawRect:(CGRect)rect right? Make sure the method signature is correct, and you don't omit the rect argument even if you don't use it. -setNeedsDisplay should be called the the subview, not self .

drawRect Doesn't want to draw anything

旧城冷巷雨未停 提交于 2019-12-12 17:29:06
问题 I have a ViewController on storyboard. I have used the interface builder to set a toolbar at the bottom of the screen. I have set the custom view to a view overrides drawRect. However, for the life of me, I cannot get anything ever to show up on screen called from that drawRect. drawRect itself is called just fine, but nothing shows up on screen. Also, I have this ViewController with a method that uses AVCaptureSession to toggle its background to a live view from camera input. I had suspected

UIView's drawRect not being called when swizzled

末鹿安然 提交于 2019-12-12 14:17:51
问题 I am experimenting with advanced Objective-C methods. What I want to achieve is to append specific drawing code to an existing UIView . I started easily, I went on to declare my own drawRect method in a category: @interface UIView (Swizzled) - (void)my_drawRect:(CGRect)rect; @end Then I swizzled the drawRect method of UIView in the implementation of the category: + (void)load { [self swizzleInstanceMethod:@selector(drawRect:) withMethod:@selector(my_drawRect:) inClass:[UIView class]]; } -

Capture UIImage of UIView stuck in DrawRect method

北城余情 提交于 2019-12-11 23:16:18
问题 I am trying to capture image of my UIView but when I call this method - (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContext(view.bounds.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } my application enter in DrawRect method of my view and stuck in loop of these lines [super drawRect:rect]; [curImage drawAtPoint:CGPointMake(0, 0)]; mid1 = midPoint

Draw line in UILabel before and after text

人走茶凉 提交于 2019-12-11 20:01:46
问题 I want to draw a line before and after a string in UILabel exactly like the following image: PS: the text is not static, so i can't tell what is the exact text width, otherwise i would put two static lines before and after the text. PS: Also i can't put the label above a line and give the label background color same to the view background because i have gradient color in the lower view. 回答1: I Hope below is what you was looking for... #import "ViewController.h" @interface ViewController () {

How to access drawrect method from UIViewController?

梦想的初衷 提交于 2019-12-11 18:10:12
问题 I am using Xcode 4.2 and have a UIViewController representing one of the scenes. In it, inside viewWillAppear i have [NSTimer scheduledTimerWithTimeInterval: FramesPerSecond target:self selector:@selector(gameLoop) userInfo:nil repeats:YES]; Inside gameLoop method, i have [[self view] setNeedsDisplay]; Problem: drawRect method is not being called (As i understand it it should be called from setNeedsDisplay Question: Is it possible to define drawRect method inside a UIViewController class and

invalid context 0x0 within custom UIView

允我心安 提交于 2019-12-11 14:23:33
问题 I have the following code for a custom view. @IBDesignable class SplitCircleView: UIView { override init(frame: CGRect) { super.init(frame: frame) draw(frame) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) draw(frame) } override func draw(_ rect: CGRect) { self.backgroundColor = .clear drawSlice(rect: self.frame, startPercent: 87.5, endPercent: 37.5, color: .green) drawSlice(rect: self.frame, startPercent: 37.5, endPercent: 87.5, color: .red) } func drawSlice(rect:

Common outline for two shapes drawn in drawRect: ObjectiveC

夙愿已清 提交于 2019-12-11 13:49:46
问题 I have two shapes in a UIView - one, an ellipse and two, a triangle drawn using UIBezierPath . I need to draw the outline of these two shapes combined. How can I do it? 回答1: You can do an "outside" stroke (like stroke->outside in photoshop/pixelmator) by calling stroke to draw the outline and setting the inverse of your shapes as the clipping path first. To do the inverse of the clipping path see this answer: https://stackoverflow.com/a/10639523/461492 (read comments too). So here are the

Button to trigger drawRect to redraw a view

北城以北 提交于 2019-12-11 11:39:18
问题 I have a VC with a subview. At the subview level I have a button. I want the button to result in the view being updated. The IBAction code is in the VC. All it currently does is toggle a BOOL value. Back in the subview drawRect: method is the code that tests the BOOL and changes the view accordingly. My observation is that when the button is pressed, the IBAction code runs, toggles the BOOL , but the drawRect: method doesn't get called. I tried calling drawRect manually (not good practice and