redribben

left image

Jan 6th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4.  
  5.  
  6. @end
  7.  
  8. @implementation ViewController
  9.  
  10. - (void)viewDidLoad {
  11.     [super viewDidLoad];
  12.     [self beginGeneratingDeviceOrientationNotifications];
  13. }
  14.  
  15. - (void)background {
  16.     UIImage *imageA = [UIImage imageNamed:@"123.png"];
  17.     CGSize imageSize = imageA.size;
  18.     CGFloat newWidth = (([[ UIScreen mainScreen ] bounds].size.height) / imageSize.height) * imageSize.width;
  19.    
  20.     UIGraphicsBeginImageContext(self.view.frame.size);
  21.     [imageA drawInRect:CGRectMake(0, 0, newWidth, [[ UIScreen mainScreen ] bounds].size.height)];
  22.     UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
  23.     UIGraphicsEndImageContext();
  24.    
  25.     self.view.backgroundColor = [UIColor colorWithPatternImage:resizedImage];
  26. }
  27.  
  28. - (void)beginGeneratingDeviceOrientationNotifications{
  29.     NSLog(@"it started");
  30.     [[NSNotificationCenter defaultCenter]
  31.      addObserver:self
  32.      selector:@selector(deviceOrientationDidChangeNotification:)
  33.      name:UIDeviceOrientationDidChangeNotification
  34.      object:nil];
  35. }
  36.  
  37. - (void)deviceOrientationDidChangeNotification:(NSNotification*)note {
  38.     [self background];
  39.     NSLog(@"it changed");
  40. }
  41.  
  42.  
  43. - (void)didReceiveMemoryWarning {
  44.     [super didReceiveMemoryWarning];
  45. }
  46.  
  47. //- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
  48. //    UIGraphicsBeginImageContext(size);
  49. //    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
  50. //    UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
  51. //    UIGraphicsEndImageContext();
  52. //    return destImage;
  53. //}
  54.  
  55.  
  56. @end
Advertisement
Add Comment
Please, Sign In to add comment