How to draw in a UIView? UIGraphics.getCurrentContext return null

314 views
Skip to first unread message

Yi-Chun Kuo

unread,
Apr 4, 2015, 9:23:17 AM4/4/15
to rob...@googlegroups.com
I try to draw a circle in a UIView. I subclass UIView as MyUIView and override "draw" function as what to do in objC. 

public class MyUIView extends UIView{

     public MyUIView(CGRect rect){

          super(rect);

      }

@Override

public void draw(CGRect rect){

      super.draw(rect);

      CGContext mCGContext = UIGraphics.getCurrentContext();

      mCGContext.setStrokeColor(UIColor.black().getCGColor());

      mCGContext.addArc(100.0, 20.0,15.0, 0.0, 2 * 3.14, 1);

      }

}

However, it has error that mCGContext is null.  I didn't have experience in iOS development. I follow how to draw in a UIView using objC here https://mikebluestein.wordpress.com/2010/02/21/drawing-with-coregraphics-in-monotouch-2/, but it seems it is not equivalent to robovm. 

  

Yi-Chun Kuo

unread,
Apr 4, 2015, 9:28:54 AM4/4/15
to rob...@googlegroups.com

  By the way, I refer to the TilingView.java in PhotoScroller of robovm sample. It also use  UIGraphics.getCurrentContext(), but I can't figure out why its currentcontext has value.

Paul Franceus

unread,
Apr 5, 2015, 1:40:14 PM4/5/15
to Yi-Chun Kuo, rob...@googlegroups.com
Are you calling draw directly yourself, or are you calling setNeedsDisplay() on the view?


On Sat, Apr 4, 2015 at 6:28 AM, Yi-Chun Kuo <kuoyic...@gmail.com> wrote:

  By the way, I refer to the TilingView.java in PhotoScroller of robovm sample. It also use  UIGraphics.getCurrentContext(), but I can't figure out why its currentcontext has value.

--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages