简体   繁体   中英

drawRect:rect how to call this method , I am using to draw a string

-(void)drawRect:(CGRect)rect
{   
    CGContextRef  context = UIGraphicsGetCurrentContext();
    CGContextSelectFont(context, "Arial", 24, kCGEncodingFontSpecific);
    CGContextSetTextPosition(context,80,80);
    CGContextShowText(context, "hello", 6);
    //not even this works
    CGContextShowTextAtPoint(context, 1,1, "hello", 6);
}

I want to know how to call the above method, I have pasted the above code into the implementation file, but don't know why it's not called when I execute the project.

Does anyone know why this could be?

setNeedsDisplay should do that for you, here is a link link text

The methods is also called when the view first displays...

Finally I got the anser, just take a new class and inherit the class with UIView instead of NSobject,

This class will give us UIView object and it will also contain the drawRect method inbuilt.

so this is How i done. it :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM