Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.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/5/objective-c/26.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/3/xpath/2.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
Ios 使用图像生成UIView_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 使用图像生成UIView

Ios 使用图像生成UIView,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,由于某种原因,我采用以下方法不显示图像: - (void)drawRect:(CGRect)rect { float cornerRadius = self.bounds.size.width/RADIUS_RATIO; UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius]; [roundedRect addCli

由于某种原因,我采用以下方法不显示图像:

- (void)drawRect:(CGRect)rect
{
    float cornerRadius = self.bounds.size.width/RADIUS_RATIO;
    UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius];
    [roundedRect addClip];
    [[UIColor whiteColor] setFill];
    UIRectFill(self.bounds);
    [[UIColor blackColor] setStroke];
    [roundedRect stroke];

    CGRect imageRect = CGRectInset(self.bounds,
                                   self.bounds.size.width * 0.5,
                                   self.bounds.size.height * 0.5);
    if (self.faceUp)
    {
        UIImage *cardFace = [UIImage imageNamed:[NSString stringWithFormat:
                                                 @"%@%@.png",[self rankAsStrings],self.suit]];
        if (cardFace)
        {
            NSLog(@"%@%@.png",[self rankAsStrings],self.suit);
            [cardFace drawInRect:imageRect];

        } else {
            NSLog(@"No Image Found: %@%@.png",[self rankAsStrings],self.suit);
        }

    } else {
        [[UIImage imageNamed:@"Back.png"] drawInRect:imageRect];
    }
}
有人能解释一下吗

另外,图像已经存在,我确实在控制台中收到了“NSLog(@“%@%@.png”,[self rankAsStrings],self.suit);”消息


TIA

我认为您的
imageRect
的宽度和高度分别为0.0和0.0。检查文档中的
CGRectInset
方法-它将原始rect减少2*dx和2*dy。

我会这样做:

myView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"MyProfilePic.png"]];

非常感谢。。。森林换树的情况在这里!