redribben

weird image

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