Updating extensions for iOS 13: Difference between revisions

From iPhone Development Wiki
No edit summary
(→‎Home Screen Layout: Demonstrate how to adjust icon grid size)
 
Line 21: Line 21:
== Home Screen Layout ==
== Home Screen Layout ==


=== SBIconListFlowLayout ===  
=== Classes ===
 
==== SBIconListFlowLayout ====  


Layout handling in iOS 13 now uses <code>SBIconListFlowLayouts</code>. These are provided by an instance of <code>SBHDefaultIconListLayoutProvider</code>.
Layout handling in iOS 13 now uses <code>SBIconListFlowLayouts</code>. These are provided by an instance of <code>SBHDefaultIconListLayoutProvider</code>.
Line 27: Line 29:
This alone handles row/column count. It also contains a <code>SBIconListGridLayoutConfiguration</code>, which controls the spacing and location of icons.
This alone handles row/column count. It also contains a <code>SBIconListGridLayoutConfiguration</code>, which controls the spacing and location of icons.


=== SBIconListGridLayoutConfiguration ===
==== SBIconListGridLayoutConfiguration ====


This class contains several properties that can be modified to alter the layout.  
This class contains several properties that can be modified to alter the layout.  


Selectors of interest include <code>portraitLayoutInsets</code> and <code>landscapeLayoutInsets</code>. These return an instance of <code>UIEdgeInsets</code> that can be used to manipulate layout.  
Selectors of interest include <code>portraitLayoutInsets</code> and <code>landscapeLayoutInsets</code>. These return an instance of <code>UIEdgeInsets</code> that can be used to manipulate layout.
 
=== Modifying number of rows and columns ===
 
It now depends on "where" you want to change the number of rows and columns. If you want to adjust the values for the icons in Home Screen (and Home Screen with Today widgets in iPad), you can conditionally apply that for the icon location <code>SBIconLocationRoot*</code>, like so:
 
%hook SBHDefaultIconListLayoutProvider
- (SBIconListGridLayout *)makeLayoutForIconLocation:(NSString *)iconLocation {
SBIconListGridLayout *layout = %orig;
if ([iconLocation hasPrefix:@"SBIconLocationRoot"]) {
SBIconListGridLayoutConfiguration *config = [layout valueForKey:@"_layoutConfiguration"];
config.numberOfLandscapeRows += 1;
config.numberOfLandscapeColumns += 2;
config.numberOfPortraitRows += 1;
config.numberOfPortraitColumns += 2;
}
return layout;
}
%end


== Generating an apps icon image ==
== Generating an apps icon image ==

Latest revision as of 04:43, 8 May 2021

Let's collect knowledge like we did with iOS 12, iOS 11, iOS 10, iOS 9, iOS 8 and iOS 7 – paste in your notes and share what you've learned, and somebody else will organize it later. :) If you want to ask questions and share tips over chat with other developers, see How to use IRC for how to connect to #theos and #iphonedev.

Hey developer, you can add your knowledge here! Yes, you! Make an account and edit this page!

If you want to see what's been recently updated on this page, you can use the wiki's history feature to compare the revisions (to look at the diff) since the last time you visited this page.

SBApplication -(FBScene*)mainScene removed

-[SBApplication mainScene] was removed in iOS 13. It can be accessed from a SBApplication by replacing [myApp mainScene] with the following:

[[FBSceneManager sharedInstance] sceneWithIdentifier:[myApp _baseSceneIdentifier]]

myApp being the name of your SBApplication instance.

SBRootIconListView

This class was removed entirely with iOS 13. Root Icon Lists are now instances of SBIconListView.

Home Screen Layout

Classes

SBIconListFlowLayout

Layout handling in iOS 13 now uses SBIconListFlowLayouts. These are provided by an instance of SBHDefaultIconListLayoutProvider.

This alone handles row/column count. It also contains a SBIconListGridLayoutConfiguration, which controls the spacing and location of icons.

SBIconListGridLayoutConfiguration

This class contains several properties that can be modified to alter the layout.

Selectors of interest include portraitLayoutInsets and landscapeLayoutInsets. These return an instance of UIEdgeInsets that can be used to manipulate layout.

Modifying number of rows and columns

It now depends on "where" you want to change the number of rows and columns. If you want to adjust the values for the icons in Home Screen (and Home Screen with Today widgets in iPad), you can conditionally apply that for the icon location SBIconLocationRoot*, like so:

%hook SBHDefaultIconListLayoutProvider

- (SBIconListGridLayout *)makeLayoutForIconLocation:(NSString *)iconLocation {
	SBIconListGridLayout *layout = %orig;
	if ([iconLocation hasPrefix:@"SBIconLocationRoot"]) {
		SBIconListGridLayoutConfiguration *config = [layout valueForKey:@"_layoutConfiguration"];
		config.numberOfLandscapeRows += 1;
		config.numberOfLandscapeColumns += 2;
		config.numberOfPortraitRows += 1;
		config.numberOfPortraitColumns += 2;
	}
	return layout;
}

%end

Generating an apps icon image

Previously an icon image could be generated from an icon object like so

SBIcon *icon = someIcon;
UIImage *iconImage = [icon generateIconImage:2];

In iOS 13 this method was changed to -generateIconImageWithInfo:(struct SBIconImageInfo)info

struct SBIconImageInfo {
    CGSize size;
    CGFloat scale;
    CGFloat continuousCornerRadius;
};
SBIconController *iconController = [NSClassFromString(@"SBIconController") sharedInstance];
SBIcon *icon = [iconController.model expectedIconForDisplayIdentifier:@"com.apple.Music"];

CGSize imageSize = CGSizeMake(60, 60);

struct SBIconImageInfo imageInfo;
imageInfo.size  = imageSize;
imageInfo.scale = [UIScreen mainScreen].scale;
imageInfo.continuousCornerRadius = 12;

UIImage *iconImage = [icon generateIconImageWithInfo:imageInfo];