Skip navigation

Tag Archives: xcode

I had a UIImageView control set up in one of my Views using Interface Builder, but I wanted to resize the UIImageView control programmatically depending on the device’s screen size.  I spent several hours trying all sorts of techniques, but I always had problems.  If I resized the UIImageView’s frame in viewDidLoad, it simply wouldn’t work.  If I resized its frame in viewDidAppear, it would work but the user would see the original-sized image before switching to the updated size which I felt was ugly and unnecessary.

I finally found a solution that would show the correctly resized UIImageView right away, but it required me to remove the UIImageView from my .XIB file, remove the outlet from Interface Builder, and remove the IBOutlet from my header file.  Then I simply programmatically added the UIImageView to the view in my viewDidLoad like so:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 173, 728, 771)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = [UIImage imageNamed:@"tutorial1.png"];
[self.view addSubview:imageView];

I was recently at wit’s end with what seemed like it should be a non-issue: I had taken a screenshot of my iPhone, cropped the image down to a single button, and was then trying to display it as the background image on a UIButton. The problem was that the image would appear twice as large. After stepping through the code, I realized that the UIImage object had a scale value of 1.0f instead of 2.0f like it should (I have an iPhone 5 with Retina Display). After some snooping around in Apple’s UIImage reference, I realized the fix was simple: I just had to add “@2x” to my image’s filename.  BUT there is one caveat:  when referencing the image’s filename in your code, do NOT add the “@2x”.

For example, if your image filename is “HelpIcon@2x.png”:

INCORRECT (image has scale factor of 1.0f and is too large)

[button setBackgroundImage: [UIImage imageNamed:@"HelpIcon@2x.png"] forState:UIControlStateNormal];

CORRECT (image has scale factor of 2.0f)

[button setBackgroundImage: [UIImage imageNamed:@"HelpIcon.png"] forState:UIControlStateNormal];

After finally submitting my first app to Apple’s App Store, I figured I should pass on some helpful tips that I learned during the process.

  1. If you have an idea for an app, go ahead and create the application in iTunes Connect now.  You will have to upload some images for icons and screenshots, but those can be changed later.  You won’t have to submit your app’s binary yet.  Why go through all of this trouble so early on?  Because it prevents any other developers from taking your app’s name! Read More »

I recently updated my Macbook Pro to Mountain Lion and then downloaded and installed Xcode 4.5.2.  I still had Xcode 3.2.6 installed as well, and my goal was to update my existing projects to the newer version.  Unfortunately when I tried to load my first project, Xcode just hung and sat there loading forever until I Force Quit it.  I soon realized that this same issue occurred even if I tried to create a new project, tried to open the Repositories tab in Organizer, or even if I hovered over Xcode’s File -> Source Control menu item.  My system log continuously showed the same error:

Nov 12 14:14:50 MacBook-Pro.local Xcode[3307]: [MT] DVTAssertions: Warning in /SourceCache/IDEFoundation/IDEFoundation-1880/Framework/Classes/Model/SourceControl/IDESourceControlTree.m:130
Details: Invalid location for source tree. Initialization failed: {
IDESourceControlRepositoryLocationKey = "";
authenticated = NO;
name = iPhone;
online = YES;
path = "";
system = "scm.subversion";
}
Object:
Method: -initWithDictionary:sourceControlExtension:sourceControlManager:
Thread: {name = (null), num = 1}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide. Read More »