简体   繁体   中英

change the background image of a view in ios

I have a class of keyboard like this:

@implementation Testkeyboard 

 -(void)drawRect:(CGRect)rect
 {

    UIImage *image = [UIImage imageNamed: @"FrameLetters2.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];  
 }

I want to create some methods to change the background *image like this

  -(void) changeImage1

  -(void) changeImage2

How it can be implemented?

Thanks in advance.

Use colorWithPatternImage method like this

-(void) changeImage1
{
self.view.backgroundColor=[UIcolor colorWithPatternImage:[UIImage imageNamed:@"image1"]];
}
-(void) changeImage2
{
self.view.backgroundColor=[UIcolor colorWithPatternImage:[UIImage imageNamed:@"image2"]];
}

我也有类似的情况,我认为最简单的方法是向视图添加UIImageView并使其填充整个视图区域。

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