iphone 设置视图背景图片

news/2024/10/17 19:30:36/
方法一,使用一个UIImageView实例做子视图,并且放最后面

Objective-c代码
  1. - (void)setBackgroundImage {  
  2.     NSLog(@"setting bg image");  
  3.     UIImageView *customBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];  
  4.     self.background = customBackground;  
  5.     [customBackground release];  
  6.       
  7.     [self addSubview:background];  
  8.     NSLog(@"Added background subview %@", background);  
  9.     [self sendSubviewToBack:background];  
  10. }  
- (void)setBackgroundImage { NSLog(@"setting bg image"); UIImageView *customBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]]; self.background = customBackground; [customBackground release]; [self addSubview:background]; NSLog(@"Added background subview %@", background); [self sendSubviewToBack:background]; }


方法二,Cook Book中提到的方法

Objective-c代码
  1. - (void)loadView {  
  2.       
  3.     UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
  4.     [contentView setImage:[UIImage imageNamed:@"Default.png"]];  
  5.     [contentView setUserInteractionEnabled:YES];  
  6.     self.view = contentView;  
  7.     [contentView release];  
  8. }  
- (void)loadView { UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; [contentView setImage:[UIImage imageNamed:@"Default.png"]]; [contentView setUserInteractionEnabled:YES]; self.view = contentView; [contentView release]; }


方法三,lvyile网友用的一个小技巧,uiView是UIView的实例,而不是UIImageView

Objective-c代码
  1. uiView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]]; 

http://www.ppmy.cn/news/327804.html

相关文章

设置ios窗口的背景图片

设置背景图片: UIImageView *tableBg [[UIImageView alloc] initWithImage:[UIImage imageNamed:"login.jpg"]]; [self.tableView setBackgroundView:tableBg]; [tableBg release];

移动端安卓和苹果手机背景图片显示不全的问题

最近写移动端的页面遇到一个坑,使用chrome浏览器调试iphone6,背景图片显示完整,但是在小米手机端浏览发现图片显示不完全; 解决办法: 安卓手机和苹果手机分辨率不同,在苹果手机上显示的是普通的2x图片&…

ios 改变背景图片

/var/mobile/Library/LockBackground.jpg /User/Library/LockBackground.png and then call notify_post(" com.apple.language.changed") 其实发别的改变也一样 就是通知系统有改变 他就会重新刷一次 这样才能载入你重写的图片

iPhone设置视图背景图片的方法

方法一,使用一个UIImageView实例做子视图,并且放最后面 Objective-c代码 - (void)setBackgroundImage { NSLog("setting bg image"); UIImageView *customBackground [[UIImageView alloc] initWithImage:[UIImage imageNamed:&…

ios:设置视图背景图片的方法

1. 使用一个UIImageView实例做子视图,并且放最后面 UIImageView *customBackgournd [UIImageView alloc] initWithImage:[UIImage imageNamed:"background.jpg"]]; self.background customBackground; [customBackground release]; [self addSubview:b…

iOS 聊天背景图

///< 因为消息的字数不固定&#xff0c;所以高度也就不固定&#xff1b;但消息背景又时常使用的是一些不规则图&#xff0c;对此我们需要对图片的中心区域进行拉伸&#xff0c;可用下面方法&#xff1a; - (UIImage *)resizableImageWithImageName:(NSString *)name { UIIm…

iphone中背景图的设置方法

iphone中背景图的设置 方法一&#xff0c;使用一个UIImageView实例做子视图&#xff0c;并且放最后面 - (void)setBackgroundImage { NSLog("setting bg image"); UIImageView *customBackground [[UIImageView alloc] initWithImage:[UIImage imageNam…

iphone添加背景图片方法

有两种方法&#xff0c; 一种是不使用nib文件&#xff0c;直接在视图控制类的代码中添加代码&#xff1a; &#xff0f;&#xff0f;在- (void)loadView{}中加入你想要加入的视图就行&#xff0c;如下&#xff1a; - (void)loadView {UIImageView *background [[UIImageView …