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"]];
非常感谢。。。森林换树的情况在这里!