我找不到任何关于你如何在使用时将'image‘居中的东西(也许你不能):
[self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]];设置我的[self setContentMode:UIContentModeCenter];没有帮助。
是否必须手动绘制图像(在drawRect中或设置CALayer的内容?哪一个更可取?
发布于 2011-09-30 15:22:14
我认为你在这里走错了路:你从一个模式创建一个UIColor (模式已经暗示这是一个重复的图像)。总而言之,你不能让你的模式不重复和居中。
如果你只是想要简单的图片作为你的UIView的背景,只要将它添加为一个子视图并居中即可。
UIImage* img = [UIImage imageNamed:@"yourfile.png"];
UIImageView* imgView = [[UIImageView alloc]initWithImage: img];
[yourUIView addSubview: imgView];
imgView.center = CGPointMake(yourUIView.frame.size.width/2, yourUIView.frame.size.height/2);现在-向你的"yourUIView“视图添加更多的子视图,它们将显示在图像的顶部-因此图像成为背景。
所以..。不需要自己画任何东西。
https://stackoverflow.com/questions/7607113
复制相似问题