Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIImageView的CGRectMake?_Objective C_Xcode_Uiimageview_Cgrect - Fatal编程技术网

Objective c UIImageView的CGRectMake?

Objective c UIImageView的CGRectMake?,objective-c,xcode,uiimageview,cgrect,Objective C,Xcode,Uiimageview,Cgrect,我正在尝试使用CGRectMake为uiimageview分配一个位置和大小,下面是代码 -(IBAction)done11 { [self performSelector:@selector(multibuttonvoid) withObject:nil afterDelay:2.0]; } -(void)multibuttonvoid { UIImageView *multibtn = [UIImageView alloc]; multibtn.i

我正在尝试使用CGRectMake为uiimageview分配一个位置和大小,下面是代码

     -(IBAction)done11 {

  [self performSelector:@selector(multibuttonvoid) withObject:nil afterDelay:2.0];



      }

  -(void)multibuttonvoid {

 UIImageView *multibtn = [UIImageView alloc];
multibtn.image = [UIImage imageNamed:@"multibuttonpic"];

multibtn = CGRectMake(159, 325, 438, 318);
  [self.view addSubview:multibtn];


      }

所以,正如您所看到的,如果我按下一个按钮,它应该会添加一个带有图片的uiimageview。但出于某种原因,我在CGRectMake行中遇到了这个错误:将uiimageview指定给不兼容的类型CGRect,我认为CGRect是一个uiimage

a
CGRect
,顾名思义,它代表一个矩形,而不是一个图像,因此您必须将它指定给图像视图的一个属性,即矩形,本例中的
框架

顾名思义,
CGRect
表示一个矩形,而不是图像,因此您必须将其指定给图像视图的一个属性,即矩形,本例中的
框架

您没有初始化
UIImageView
。尝试调用
-(id)initWithImage:(UIImage*)image
givig
nil
,然后设置
image
frame
属性

UIImageView *multibtn = [[UIImageView alloc] initWithImage:nil];
multibtn.image = [UIImage imageNamed:@"multibuttonpic"];
multibtn.frame = CGRectMake(159, 325, 438, 318);
[self.view addSubview:multibtn];


您没有初始化您的
UIImageView
。尝试调用
-(id)initWithImage:(UIImage*)image
givig
nil
,然后设置
image
frame
属性

UIImageView *multibtn = [[UIImageView alloc] initWithImage:nil];
multibtn.image = [UIImage imageNamed:@"multibuttonpic"];
multibtn.frame = CGRectMake(159, 325, 438, 318);
[self.view addSubview:multibtn];


CGRect、UIImage和UIImageView是完全不同的东西

CGRect是一种简单的结构,使用点(原点)和大小(大小)在任意坐标空间中定义矩形

UIImage是图像和相关元数据

UIImageView是用于显示UIImage的UIView

看起来您真正想要的是设置UIImageView的
frame
属性,以指示它在屏幕上的显示位置:

multibtn.frame = CGRectMake(159, 325, 438, 318);
另外,顺便说一句,不要忘记通过调用UIImageView上的
initWithImage:
initWithFrame:
,或者类似的方法来初始化UIImageView。这通常与分配同时进行:

UIImageView *multibtn = [[UIImageView alloc] initWithImage:...];

CGRect、UIImage和UIImageView是完全不同的东西

CGRect是一种简单的结构,使用点(原点)和大小(大小)在任意坐标空间中定义矩形

UIImage是图像和相关元数据

UIImageView是用于显示UIImage的UIView

看起来您真正想要的是设置UIImageView的
frame
属性,以指示它在屏幕上的显示位置:

multibtn.frame = CGRectMake(159, 325, 438, 318);
另外,顺便说一句,不要忘记通过调用UIImageView上的
initWithImage:
initWithFrame:
,或者类似的方法来初始化UIImageView。这通常与分配同时进行:

UIImageView *multibtn = [[UIImageView alloc] initWithImage:...];

对不起,各位,我在发帖后一秒钟就意识到了这一点,我很抱歉CARELESS@user842059:没问题。但是请不要用大写字母发帖,它读起来好像你在大喊大叫(而且弄伤了我的耳朵)。哦,我很抱歉,我已经用图片做了第一步,在我发帖后,我意识到了我所有的错误。每个人,我在发帖后一秒钟就意识到了这一点,我很抱歉CARELESS@user842059:没问题。但是请不要用大写字母发帖,它读起来好像你在大喊大叫(而且伤了我的耳朵)。哦,我很抱歉,我已经用图片做了第一步,在我发帖后,我意识到了我所有的错误。每个人我在发帖后一秒钟意识到了这一点,我非常小心,每个人我在发帖后一秒钟意识到了这一点,我太小心了,各位,我发帖子一秒钟后就意识到了这一点,粗心,对不起,各位,我发帖子一秒钟后就意识到了这一点,粗心