≡ Menu

5 practical tips for developers optimizing your apps for iOS7

5pm app

With iOS7 out every iOS developer found themselves with the task of optimizing their existing apps for the new iOS.

While updating our 5pm iPhone app, our developers ran into different issues they had to address. Since other developers may face the same problems, we decided to share what we have learned.

Below are just five practical solutions you may need when optimizing your  app for iOs 7. Feel free to add more in the comments – it may save other developers some time.

1. We are using a layout where there is a UITextView with a fixed width, but its height is based on its content size. In iOS 6.1 checking the contentsize.height and setting it as the text view’s frame height was enough, but it does not work anymore in iOS 7.
Solution: Use the method sizeThatFits – it works in  both ios6 and ios7.
CGSize textViewSize = [self.myTextView sizeThatFits:CGSizeMake(self.myTextView.frame.size.width, FLT_MAX)];
self.myTextView.height = textViewSize.height;
2. The status bar became transparent in iOS7. As a result, if an application has a dark background, you will not see anything there, only a green battery indicator in the corner.
Solution: Change the style of status bar:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Solution:  UITableView has a property separatorInset. You can use that to set the insets of the table view separators to zero to let them span the full width of the screen.
[self.tableView setSeparatorInset:UIEdgeInsetsZero];

 

4. If you need to show hierarchical data in a table view, you can implement this method:
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
in your UITableViewDelegate class.
In iOS6 it shifts the images and content, but in ios7 – only content. As a result you’ll get something like that.
Solution:  To fix that you have to subclass UITableViewCell and override the layoutSubViews method:
- (void)layoutSubviews
{
// Call super
[super layoutSubviews];
// Update the separator
self.separatorInset = UIEdgeInsetsMake(0, (self.indentationLevel * self.indentationWidth) + 15, 0, 0);
// Update the frame of the image view
self.imageView.frame = CGRectMake(self.imageView.frame.origin.x + (self.indentationLevel * self.indentationWidth), self.imageView.frame.origin.y, self.imageView.frame.size.width, self.imageView.frame.size.height);
// Update the frame of the text label
self.textLabel.frame = CGRectMake(self.imageView.frame.origin.x + 40, self.textLabel.frame.origin.y, self.frame.size.width - (self.imageView.frame.origin.x + 60), self.textLabel.frame.size.height);
// Update the frame of the subtitle label
self.detailTextLabel.frame = CGRectMake(self.imageView.frame.origin.x + 40, self.detailTextLabel.frame.origin.y, self.frame.size.width - (self.imageView.frame.origin.x + 60), self.detailTextLabel.frame.size.height);
}
 As a result, your table view will look as you expect it to look.

 

5. If you are trying to set a background image for UIButton it could work not as you expect: the button will be filled with blue color. It happens because in  iOS7 there is a new button type called UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), standard system button.
Solution: To fix that you can change the button type to “Custom” in Xcode UI Builder or do it programmatically

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

{ 3 comments… add one }
  • Anne December 10, 2013, 11:40 am

    Thanks for the tips! We are working on a mobile app for our product and the info is timely.

  • john May 25, 2014, 9:55 am

    Thanks for the tips. I came cross them when we are trying to solve the cell indentation problem as you pointed out. The tip is really helpful. However, I think that there is another major UI change with iOS7, that the UIAlertView no longer take any subclasses, and can’t be customised to display text inputs and progress bars. Any suggestions on that?

  • 5pm Team June 3, 2014, 1:00 pm

    john>
    You have to assign to the key accessoryView the value of the custom view. It is important to do that before calling [alertView show]:

    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 160, 30)];
    textField.borderStyle = UITextBorderStyleLine;

    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@”UIAlert with textview”
    message:@””
    delegate:nil
    cancelButtonTitle:@”NO”
    otherButtonTitles:@”YES”, nil];
    [av setValue:textField forKey:@”accessoryView”];
    [av show];

    I hope this helps.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.