ios:设置视图背景图片的方法
2014-08-13 23:02
621 查看
1. 使用一个UIImageView实例做子视图,并且放最后面
UIImageView *customBackgournd = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
self.background = customBackground;
[customBackground release];
[self addSubview:background];
[self sendSubViewToBack:background];
如果是用ib,就在xib文件中添加UIImageView,放在最下面。
2.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];
推荐使用这种,方便。
今天在代码中使用
self.view.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"instrument_bg@2x.png"]];
结果导致instrument_bg@2x.png这张图片本来是640x960的,结果显示的时候只显示了左边一半出来与上面一半出来。
正确的代码应该是
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"instrument_bg"]];
这样的话,会自动去匹配图片。
错误的写法导致了图片放大了2倍,所以看起来就只有一半了。另外图片的后缀一般也省略为好
UIImageView *customBackgournd = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
self.background = customBackground;
[customBackground release];
[self addSubview:background];
[self sendSubViewToBack:background];
如果是用ib,就在xib文件中添加UIImageView,放在最下面。
2.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];
推荐使用这种,方便。
今天在代码中使用
self.view.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"instrument_bg@2x.png"]];
结果导致instrument_bg@2x.png这张图片本来是640x960的,结果显示的时候只显示了左边一半出来与上面一半出来。
正确的代码应该是
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"instrument_bg"]];
这样的话,会自动去匹配图片。
错误的写法导致了图片放大了2倍,所以看起来就只有一半了。另外图片的后缀一般也省略为好
相关文章推荐
- ios:设置视图背景图片的方法
- ios:设置视图背景图片的方法
- ios:设置视图背景图片的方法
- ios UIView设置背景图片的方法
- iOS开发笔记--关于设置UIView的背景为图片的方法以及问题
- iPhone设置视图背景图片的方法
- ios UIView设置背景图片的方法
- ios 5.0 设置navigationbar / toolbar 背景图片的方法 (以前用的设置navgationbar的背景图片的方法已经失效)
- IOS开发:关于设置UIView的背景为图片的方法以及问题
- IOS开发:关于设置UIView的背景为图片的方法以及问题
- iPhone设置视图背景图片的方法
- iPhone设置视图背景图片的方法
- IOS开发:关于设置UIView的背景为图片的方法以及问题
- iOS开发笔记--关于设置UIView的背景为图片的方法以及问题
- iOS中设置视图的背景图片
- iPhone设置视图背景图片的方法
- iphone iPhone开发中为UINavigationBar设置背景图片方法
- MFC中设置对话框颜色、添加背景图片、添加音乐的方法
- 设置UIView 背景图片二方法
- JPanel的背景图片设置方法