1.h
- (Void) DrawMyRect;
1.m
- (Void) drawMyRect
{
CGRect rect = CGRectMake (20.0f, 20,0 f, 20.0f, 20.0f);
UIImage * image = [UIImage imageNamed: @ "China.gif"];
[Image drawInRect: rect];
drawRect: rect; / / system functions.
}
Why not draw;
Reply:
Why can not draw? Probably not the place calling code.
I tested the code itself is no problem, my steps are as follows, and I hope to help you.
1 generates a viewbase project,
2 Add a MyView class, this class inherits from UIView.
3 MyView function - (void) drawRect:. (CGRect) rect add the following code
CGRect frame = CGRectMake (20.0f, 20,0 f, 20.0f, 20.0f);
UIImage * image = [UIImage imageNamed: @ "China.gif"];
[Image drawInRect: frame];
4 in default of your project generated viewController class -. (Void) viewDidLoad function to add the following code
MyView * _mv = [[MyView alloc] initWithFrame: CGRectMake (0,0,320,480)];
[Self.view addSubview: _mv];
5-editing project
I want to look at several aspects need attention:
1 Where to call your code? You can not call this code in viewcontroller, I personally feel that it must be used in a view class drawRect.
2 gif file if you have a problem? Png image format because I have been, so it is not clear whether all of the gif support, so can you edit your xib, put one in the above image view control, and then use the property to specify the use of gif file, to see if the display out.
3. Whether the input file name wrong? Of course, this does not generally occur.
Good luck.
Reply:
Thank you very much, I just wanted to write a function which includes drawRect, because a lot of places have to call this function to draw, size, need to change the picture, so to five parameters. If the direct use drawRect to draw, then command it, all have to be redrawn. You see my function, I hope you can understand my intention, thank you.
+ (Void) DrawCard: (float) ptx: (float) pty: (int) mx: (int) my: (NSString *) string
{
CGRect rect = CGRectMake (ptx + mx * 5, pty + my * 5,20,20);
UIImage * image = [UIImage imageNamed (@ "string")];
image.drawInRect (rect);
drawRect: rect; / / system function
}
This function draw cards, each card out, I'm going to call again, only the function of the system on their own inside a function, it can.
Thank you, I hope you can understand my intention.
Reply:
About this, I have no good way, but I recommend the following, please use uiimageview, so you can call anywhere in the viewcontroller, you think about it. Of course, this approach will have a performance problem, then you can use opengles technology.
Reply:
Can you write a function, the function of UIImageView included, I just want to set four parameters (size), and then call this function directly, I have studied two weeks, or do not come, maybe this month are fired,
Reply:
Absolutely can, ah, you think about how to achieve, if not enough, you wrote to me tomorrow. nicktc78@hotmail.com
Reply:
Code has been sent to the landlord, do not share to a third party, thank you!
No comments:
Post a Comment