1

I have the following code in my uiviewcontroller that is embed in a uinavigationcontroller.

In viewDidLoad:

[self addLogo];

Below:

- (void) addLogo
{
    UIImage *image = [UIImage imageNamed:@"logoblack.png"];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:image];

    myImageView.frame = CGRectMake(0, 0, 30, 30);
    myImageView.layer.cornerRadius = 5.0;
    myImageView.layer.masksToBounds = YES;
    myImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    myImageView.layer.borderWidth = 0.1;

   self.navigationItem.titleView = myImageView;
}

The image I have is 434 by 434 but I want it to be 30 by 30. Instead it is streched and overtakes my < Back button in the navigation bar. Is there a scale method?

cdub
  • 24,555
  • 57
  • 174
  • 303

1 Answers1

3

use

myImageView.contentMode = UIViewContentModeScaleAspectFill;

so that the imageview will not be streched , and keep its aspect

lanbo
  • 1,678
  • 12
  • 12