PFLogInViewController logo flattened

271 Views Asked by At

When customizing (by subclassing) PFLogInViewController; I have a problem with the logo. I use a square picture which for some reason gets distorted, in fact flattened.

Here is the code:

UIImage *logoImage;
logoImage = [UIImage imageNamed:@"myLogo.png"]; // 152 x 152 pixels.
self.logInView.logo = [[UIImageView alloc] initWithImage:logoImage];
self.logInView.logo.layer.cornerRadius = 7.0;
self.logInView.logo.clipsToBounds = YES;

Am I doing something wrong? Or is the issue in a different place?

2

There are 2 best solutions below

1
Dare On

Setting the image property does not change the size of a UIImageView. Call sizeToFit to adjust the size of the view to match the image. You could also set its frame explicitly to 152x152 with self.logInView.logo.frame = CGRectMake(0,0,152,152); or something similar. The other thing to check out is the image view's content mode. Maybe UIViewContentModeCenter or UIViewContentModeScaleAspectFit.

0
Kelvin Lau On

I ran into the same problem, and after viewing Dare's answer, I came up with a solution.

Override viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    let logo = UIImageView(image: UIImage(named: "logo"))
    logo.contentMode = .ScaleAspectFill
    logInView!.logo = logo
}

This solved my scaling issue. However, depending on the size of your logo, it may possibly bleed out of the screen. A dirty workaround is overriding viewDidLayoutSubviews and hardcoding the logo object's origin:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    logInView!.logo!.frame.origin.y += 200 //here I moved the logo down by 200 points
}