如何将图像添加到UIView?这是我到目前为止所尝试的:
UIView *imageHolder = [[UIView alloc] initWithFrame:CGRectMake(40,200,280,192)]; UIImage *image = [UIImage imageNamed:@"bloodymoon.jpg"]; [imageHolder addSubview:image]; // Error: Incompatible pointer types [self.mainView addSubview:imageHolder];
解决方法
试试UIImageView:
UIImageView *imageHolder = [[UIImageView alloc] initWithFrame:CGRectMake(40,192)]; UIImage *image = [UIImage imageNamed:@"bloodymoon.jpg"]; imageHolder.image = image; // optional: // [imageHolder sizeToFit]; [self.mainView addSubview:imageHolder];