如何绘制图像

sai*_*esh 0 iphone

我需要在UIView上绘制一个.png图像.我不知道如何做到这一点.有没有办法做到这一点,而不是使用UIImageView.请指导我.

Can*_*der 5

你可以使用drawAtPoint或的drawInRect方法UIImage.

例如,你可以继承UIView(我实际上假设你已经拥有),并在里面使用这个代码drawRect:

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"foo.png"];

    [image drawAtPoint:CGPointMake(0,0)];
    /* or */
    [image drawInRect:rect];
    /* or */
    [image drawInRect:CGRectMake(0,0,100,100)];
}
Run Code Online (Sandbox Code Playgroud)

有关更多方法(Alpha透明度,模式),请参阅UIImage类参考.