preface

Recently, I found that my and setting interfaces of many apps are almost the same, so I spent some time to sort out a general tool for integrating setting interface, GKSetting, which I would like to share here

Function is introduced

There are four main items added to the tool, all of which inherit from GKSettingItem.

The GKSettingItem function allows you to set the height, image, font color, background color, and selected color of the cell. Its subclasses are:

  1. GKSettingArrowItem: Cell with right arrow, right arrow can be hidden
  2. GKSettingIconItem: cell used to modify the profile picture and set the position of the picture
  3. GKSettingSwitchItem: the cell with the switch on the right needs to set the key value and the default status. You can obtain the status of the key value using GKSettingTool
  4. GKSettingExitItem: used for logging out and setting the text color.

Method of use

First of all, the overall use method is divided into the following four steps:

  1. Create GKSettingView and add it to the view
  2. Create GKSettingItem and set its properties
  3. Create a GKSettingGroup and set its properties
  4. Add GKSettingGroup to allGroups in GKSettingView, refresh

Specific usage method (GKSettingIconItem as an example) :

- (void)addIconGroup {// Create iconItem GKSettingIconItem *iconItem = [GKSettingIconItem itemWithIcon:@"icon" text:@"Username"]; iconItem.detailStyle = GKSettingDetailStyleBottom; // Set the detailTextLabel location iconitem.detailText = @"Wechat id: 12345"; iconItem.detailTextFont = [UIFont systemFontOfSize:13]; iconItem.detailTextColor = [UIColor blackColor]; iconItem.cellHeight = 95; // Set cell height to iconitem. iconSize = CGSizeMake(70, 70); / / set the image size iconItem. IconCornerRadius = 5; Operation = ^{// Set cell click GKPersonalViewController *personalVC = [GKPersonalViewController new]; personalVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:personalVC animated:YES]; }; GKSettingGroup *iconGroup = [GKSettingGroup new]; iconGroup.items = @[iconItem]; iconGroup.headerHeight = 15; // Set sectionHeader height icongroup. footerHeight = 0; / / set sectionFooter height / / added to GKSettingView [self. SettingView. AllGroups addObject: iconGroup]; }Copy the code

The effect picture after setting:

Head portrait

The other items are used in much the same way, and the corresponding properties need to be set.

The Demo rendering

test1.png

test2.png

me.png

setting.png

notify.png

The last

If you think this tool is good, click star. Your encouragement is my motivation 🙂. I am an iOS program ape, love programming, willing to share, welcome everyone to exchange and learn together.

Demo address: GKSetting Simple book address: ios-gksetting