简体   繁体   English

在ios中更改视图的背景图像

[英]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 我想创建一些方法来更改背景* image这样

  -(void) changeImage1

  -(void) changeImage2

How it can be implemented? 如何实施?

Thanks in advance. 提前致谢。

Use colorWithPatternImage method like this 像这样使用colorWithPatternImage方法

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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