├── .gitignore ├── 1.png ├── 2.gif ├── 3.png ├── README.md └── XBSettingControllerDemo ├── XBSettingControllerDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── XBSettingControllerDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── DemoMeController.h ├── DemoMeController.m ├── DemoSettingController.h ├── DemoSettingController.m ├── Imges ├── icon-arrow1@2x.png ├── icon-list01@2x.png └── icon-new@2x.png ├── Info.plist ├── XBSettingController ├── Category │ ├── UIView+XBExtension.h │ └── UIView+XBExtension.m ├── Const │ └── XBConst.h ├── Model │ ├── XBSettingItemModel.h │ ├── XBSettingItemModel.m │ ├── XBSettingSectionModel.h │ └── XBSettingSectionModel.m └── View │ ├── XBMeHeaderView.h │ ├── XBMeHeaderView.m │ ├── XBMeHeaderView.xib │ ├── XBSettingCell.h │ └── XBSettingCell.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/1.png -------------------------------------------------------------------------------- /2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/2.gif -------------------------------------------------------------------------------- /3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XBSettingController 2 | 简单配置即可快速搭建类个人中心及应用设置界面 3 | 4 | ## 效果图 5 | ![效果图](https://github.com/changjianfeishui/XBSettingController/raw/master/2.gif) 6 | 7 | ## 参数说明 8 | 9 | ![参数图](https://github.com/changjianfeishui/XBSettingController/raw/master/1.png) 10 | 11 | ![参数图](https://github.com/changjianfeishui/XBSettingController/raw/master/3.png) 12 | 13 | 14 | ## 使用说明 15 | 16 | 使用方法参见Demo,本来打算封装一个基类供继承使用,但这样可定制性就差了,因此使用还是需要实现UITableView的dataSource和delegate,如果效果图中效果可以满足需求的话,可以直接复制使用.否则,更细致的定制修改请自行修改相关源码. 17 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 37DD22CE1BB243AC00D31310 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22CD1BB243AC00D31310 /* main.m */; }; 11 | 37DD22D11BB243AC00D31310 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22D01BB243AC00D31310 /* AppDelegate.m */; }; 12 | 37DD22D71BB243AC00D31310 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37DD22D51BB243AC00D31310 /* Main.storyboard */; }; 13 | 37DD22D91BB243AC00D31310 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37DD22D81BB243AC00D31310 /* Assets.xcassets */; }; 14 | 37DD22DC1BB243AC00D31310 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37DD22DA1BB243AC00D31310 /* LaunchScreen.storyboard */; }; 15 | 37DD22EA1BB247D400D31310 /* XBMeHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22E61BB247D400D31310 /* XBMeHeaderView.m */; settings = {ASSET_TAGS = (); }; }; 16 | 37DD22EB1BB247D400D31310 /* XBMeHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 37DD22E71BB247D400D31310 /* XBMeHeaderView.xib */; settings = {ASSET_TAGS = (); }; }; 17 | 37DD22EC1BB247D400D31310 /* XBSettingCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22E91BB247D400D31310 /* XBSettingCell.m */; settings = {ASSET_TAGS = (); }; }; 18 | 37DD22F21BB2488B00D31310 /* XBSettingItemModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22EF1BB2488B00D31310 /* XBSettingItemModel.m */; settings = {ASSET_TAGS = (); }; }; 19 | 37DD22F31BB2488B00D31310 /* XBSettingSectionModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22F11BB2488B00D31310 /* XBSettingSectionModel.m */; settings = {ASSET_TAGS = (); }; }; 20 | 37DD22F71BB24A1A00D31310 /* DemoMeController.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22F61BB24A1A00D31310 /* DemoMeController.m */; settings = {ASSET_TAGS = (); }; }; 21 | 37DD22FA1BB24A2E00D31310 /* DemoSettingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22F91BB24A2E00D31310 /* DemoSettingController.m */; settings = {ASSET_TAGS = (); }; }; 22 | 37DD22FE1BB24D5B00D31310 /* UIView+XBExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 37DD22FD1BB24D5B00D31310 /* UIView+XBExtension.m */; settings = {ASSET_TAGS = (); }; }; 23 | 37DD23221BB2504400D31310 /* icon-arrow1@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 37DD230D1BB2504400D31310 /* icon-arrow1@2x.png */; settings = {ASSET_TAGS = (); }; }; 24 | 37DD23231BB2504400D31310 /* icon-list01@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 37DD230E1BB2504400D31310 /* icon-list01@2x.png */; settings = {ASSET_TAGS = (); }; }; 25 | 37DD23291BB2504400D31310 /* icon-new@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 37DD23141BB2504400D31310 /* icon-new@2x.png */; settings = {ASSET_TAGS = (); }; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 37DD22C91BB243AC00D31310 /* XBSettingControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XBSettingControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 37DD22CD1BB243AC00D31310 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | 37DD22CF1BB243AC00D31310 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 32 | 37DD22D01BB243AC00D31310 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 33 | 37DD22D61BB243AC00D31310 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | 37DD22D81BB243AC00D31310 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 35 | 37DD22DB1BB243AC00D31310 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 36 | 37DD22DD1BB243AC00D31310 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 37DD22E51BB247D400D31310 /* XBMeHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XBMeHeaderView.h; sourceTree = ""; }; 38 | 37DD22E61BB247D400D31310 /* XBMeHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XBMeHeaderView.m; sourceTree = ""; }; 39 | 37DD22E71BB247D400D31310 /* XBMeHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = XBMeHeaderView.xib; sourceTree = ""; }; 40 | 37DD22E81BB247D400D31310 /* XBSettingCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XBSettingCell.h; sourceTree = ""; }; 41 | 37DD22E91BB247D400D31310 /* XBSettingCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XBSettingCell.m; sourceTree = ""; }; 42 | 37DD22EE1BB2488B00D31310 /* XBSettingItemModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XBSettingItemModel.h; sourceTree = ""; }; 43 | 37DD22EF1BB2488B00D31310 /* XBSettingItemModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XBSettingItemModel.m; sourceTree = ""; }; 44 | 37DD22F01BB2488B00D31310 /* XBSettingSectionModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XBSettingSectionModel.h; sourceTree = ""; }; 45 | 37DD22F11BB2488B00D31310 /* XBSettingSectionModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XBSettingSectionModel.m; sourceTree = ""; }; 46 | 37DD22F51BB24A1A00D31310 /* DemoMeController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoMeController.h; sourceTree = ""; }; 47 | 37DD22F61BB24A1A00D31310 /* DemoMeController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoMeController.m; sourceTree = ""; }; 48 | 37DD22F81BB24A2E00D31310 /* DemoSettingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoSettingController.h; sourceTree = ""; }; 49 | 37DD22F91BB24A2E00D31310 /* DemoSettingController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoSettingController.m; sourceTree = ""; }; 50 | 37DD22FC1BB24D5B00D31310 /* UIView+XBExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+XBExtension.h"; sourceTree = ""; }; 51 | 37DD22FD1BB24D5B00D31310 /* UIView+XBExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+XBExtension.m"; sourceTree = ""; }; 52 | 37DD22FF1BB24DA400D31310 /* XBConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XBConst.h; sourceTree = ""; }; 53 | 37DD230D1BB2504400D31310 /* icon-arrow1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-arrow1@2x.png"; sourceTree = ""; }; 54 | 37DD230E1BB2504400D31310 /* icon-list01@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-list01@2x.png"; sourceTree = ""; }; 55 | 37DD23141BB2504400D31310 /* icon-new@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-new@2x.png"; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 37DD22C61BB243AC00D31310 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 37DD22C01BB243AC00D31310 = { 70 | isa = PBXGroup; 71 | children = ( 72 | 37DD22CB1BB243AC00D31310 /* XBSettingControllerDemo */, 73 | 37DD22CA1BB243AC00D31310 /* Products */, 74 | ); 75 | sourceTree = ""; 76 | }; 77 | 37DD22CA1BB243AC00D31310 /* Products */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 37DD22C91BB243AC00D31310 /* XBSettingControllerDemo.app */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | 37DD22CB1BB243AC00D31310 /* XBSettingControllerDemo */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 37DD22E31BB244C100D31310 /* XBSettingController */, 89 | 37DD22CF1BB243AC00D31310 /* AppDelegate.h */, 90 | 37DD22D01BB243AC00D31310 /* AppDelegate.m */, 91 | 37DD22D51BB243AC00D31310 /* Main.storyboard */, 92 | 37DD22F51BB24A1A00D31310 /* DemoMeController.h */, 93 | 37DD22F61BB24A1A00D31310 /* DemoMeController.m */, 94 | 37DD22F81BB24A2E00D31310 /* DemoSettingController.h */, 95 | 37DD22F91BB24A2E00D31310 /* DemoSettingController.m */, 96 | 37DD22D81BB243AC00D31310 /* Assets.xcassets */, 97 | 37DD22DA1BB243AC00D31310 /* LaunchScreen.storyboard */, 98 | 37DD22DD1BB243AC00D31310 /* Info.plist */, 99 | 37DD22CC1BB243AC00D31310 /* Supporting Files */, 100 | ); 101 | path = XBSettingControllerDemo; 102 | sourceTree = ""; 103 | }; 104 | 37DD22CC1BB243AC00D31310 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 37DD23001BB2504400D31310 /* Imges */, 108 | 37DD22CD1BB243AC00D31310 /* main.m */, 109 | ); 110 | name = "Supporting Files"; 111 | sourceTree = ""; 112 | }; 113 | 37DD22E31BB244C100D31310 /* XBSettingController */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 37DD22FB1BB24D5B00D31310 /* Category */, 117 | 37DD22F41BB249B600D31310 /* Const */, 118 | 37DD22ED1BB2488B00D31310 /* Model */, 119 | 37DD22E41BB247D400D31310 /* View */, 120 | ); 121 | path = XBSettingController; 122 | sourceTree = ""; 123 | }; 124 | 37DD22E41BB247D400D31310 /* View */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 37DD22E51BB247D400D31310 /* XBMeHeaderView.h */, 128 | 37DD22E61BB247D400D31310 /* XBMeHeaderView.m */, 129 | 37DD22E71BB247D400D31310 /* XBMeHeaderView.xib */, 130 | 37DD22E81BB247D400D31310 /* XBSettingCell.h */, 131 | 37DD22E91BB247D400D31310 /* XBSettingCell.m */, 132 | ); 133 | path = View; 134 | sourceTree = ""; 135 | }; 136 | 37DD22ED1BB2488B00D31310 /* Model */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 37DD22EE1BB2488B00D31310 /* XBSettingItemModel.h */, 140 | 37DD22EF1BB2488B00D31310 /* XBSettingItemModel.m */, 141 | 37DD22F01BB2488B00D31310 /* XBSettingSectionModel.h */, 142 | 37DD22F11BB2488B00D31310 /* XBSettingSectionModel.m */, 143 | ); 144 | path = Model; 145 | sourceTree = ""; 146 | }; 147 | 37DD22F41BB249B600D31310 /* Const */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 37DD22FF1BB24DA400D31310 /* XBConst.h */, 151 | ); 152 | path = Const; 153 | sourceTree = ""; 154 | }; 155 | 37DD22FB1BB24D5B00D31310 /* Category */ = { 156 | isa = PBXGroup; 157 | children = ( 158 | 37DD22FC1BB24D5B00D31310 /* UIView+XBExtension.h */, 159 | 37DD22FD1BB24D5B00D31310 /* UIView+XBExtension.m */, 160 | ); 161 | path = Category; 162 | sourceTree = ""; 163 | }; 164 | 37DD23001BB2504400D31310 /* Imges */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 37DD230D1BB2504400D31310 /* icon-arrow1@2x.png */, 168 | 37DD230E1BB2504400D31310 /* icon-list01@2x.png */, 169 | 37DD23141BB2504400D31310 /* icon-new@2x.png */, 170 | ); 171 | path = Imges; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXGroup section */ 175 | 176 | /* Begin PBXNativeTarget section */ 177 | 37DD22C81BB243AC00D31310 /* XBSettingControllerDemo */ = { 178 | isa = PBXNativeTarget; 179 | buildConfigurationList = 37DD22E01BB243AC00D31310 /* Build configuration list for PBXNativeTarget "XBSettingControllerDemo" */; 180 | buildPhases = ( 181 | 37DD22C51BB243AC00D31310 /* Sources */, 182 | 37DD22C61BB243AC00D31310 /* Frameworks */, 183 | 37DD22C71BB243AC00D31310 /* Resources */, 184 | ); 185 | buildRules = ( 186 | ); 187 | dependencies = ( 188 | ); 189 | name = XBSettingControllerDemo; 190 | productName = XBSettingControllerDemo; 191 | productReference = 37DD22C91BB243AC00D31310 /* XBSettingControllerDemo.app */; 192 | productType = "com.apple.product-type.application"; 193 | }; 194 | /* End PBXNativeTarget section */ 195 | 196 | /* Begin PBXProject section */ 197 | 37DD22C11BB243AC00D31310 /* Project object */ = { 198 | isa = PBXProject; 199 | attributes = { 200 | LastUpgradeCheck = 0700; 201 | ORGANIZATIONNAME = XB; 202 | TargetAttributes = { 203 | 37DD22C81BB243AC00D31310 = { 204 | CreatedOnToolsVersion = 7.0; 205 | DevelopmentTeam = D7QAYQ4DU5; 206 | }; 207 | }; 208 | }; 209 | buildConfigurationList = 37DD22C41BB243AC00D31310 /* Build configuration list for PBXProject "XBSettingControllerDemo" */; 210 | compatibilityVersion = "Xcode 3.2"; 211 | developmentRegion = English; 212 | hasScannedForEncodings = 0; 213 | knownRegions = ( 214 | en, 215 | Base, 216 | ); 217 | mainGroup = 37DD22C01BB243AC00D31310; 218 | productRefGroup = 37DD22CA1BB243AC00D31310 /* Products */; 219 | projectDirPath = ""; 220 | projectRoot = ""; 221 | targets = ( 222 | 37DD22C81BB243AC00D31310 /* XBSettingControllerDemo */, 223 | ); 224 | }; 225 | /* End PBXProject section */ 226 | 227 | /* Begin PBXResourcesBuildPhase section */ 228 | 37DD22C71BB243AC00D31310 /* Resources */ = { 229 | isa = PBXResourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 37DD22DC1BB243AC00D31310 /* LaunchScreen.storyboard in Resources */, 233 | 37DD22D91BB243AC00D31310 /* Assets.xcassets in Resources */, 234 | 37DD23291BB2504400D31310 /* icon-new@2x.png in Resources */, 235 | 37DD23231BB2504400D31310 /* icon-list01@2x.png in Resources */, 236 | 37DD22D71BB243AC00D31310 /* Main.storyboard in Resources */, 237 | 37DD22EB1BB247D400D31310 /* XBMeHeaderView.xib in Resources */, 238 | 37DD23221BB2504400D31310 /* icon-arrow1@2x.png in Resources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | /* End PBXResourcesBuildPhase section */ 243 | 244 | /* Begin PBXSourcesBuildPhase section */ 245 | 37DD22C51BB243AC00D31310 /* Sources */ = { 246 | isa = PBXSourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | 37DD22F21BB2488B00D31310 /* XBSettingItemModel.m in Sources */, 250 | 37DD22FA1BB24A2E00D31310 /* DemoSettingController.m in Sources */, 251 | 37DD22D11BB243AC00D31310 /* AppDelegate.m in Sources */, 252 | 37DD22EC1BB247D400D31310 /* XBSettingCell.m in Sources */, 253 | 37DD22CE1BB243AC00D31310 /* main.m in Sources */, 254 | 37DD22F71BB24A1A00D31310 /* DemoMeController.m in Sources */, 255 | 37DD22FE1BB24D5B00D31310 /* UIView+XBExtension.m in Sources */, 256 | 37DD22F31BB2488B00D31310 /* XBSettingSectionModel.m in Sources */, 257 | 37DD22EA1BB247D400D31310 /* XBMeHeaderView.m in Sources */, 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | /* End PBXSourcesBuildPhase section */ 262 | 263 | /* Begin PBXVariantGroup section */ 264 | 37DD22D51BB243AC00D31310 /* Main.storyboard */ = { 265 | isa = PBXVariantGroup; 266 | children = ( 267 | 37DD22D61BB243AC00D31310 /* Base */, 268 | ); 269 | name = Main.storyboard; 270 | sourceTree = ""; 271 | }; 272 | 37DD22DA1BB243AC00D31310 /* LaunchScreen.storyboard */ = { 273 | isa = PBXVariantGroup; 274 | children = ( 275 | 37DD22DB1BB243AC00D31310 /* Base */, 276 | ); 277 | name = LaunchScreen.storyboard; 278 | sourceTree = ""; 279 | }; 280 | /* End PBXVariantGroup section */ 281 | 282 | /* Begin XCBuildConfiguration section */ 283 | 37DD22DE1BB243AC00D31310 /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ALWAYS_SEARCH_USER_PATHS = NO; 287 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 288 | CLANG_CXX_LIBRARY = "libc++"; 289 | CLANG_ENABLE_MODULES = YES; 290 | CLANG_ENABLE_OBJC_ARC = YES; 291 | CLANG_WARN_BOOL_CONVERSION = YES; 292 | CLANG_WARN_CONSTANT_CONVERSION = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_EMPTY_BODY = YES; 295 | CLANG_WARN_ENUM_CONVERSION = YES; 296 | CLANG_WARN_INT_CONVERSION = YES; 297 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 298 | CLANG_WARN_UNREACHABLE_CODE = YES; 299 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 300 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 301 | COPY_PHASE_STRIP = NO; 302 | DEBUG_INFORMATION_FORMAT = dwarf; 303 | ENABLE_STRICT_OBJC_MSGSEND = YES; 304 | ENABLE_TESTABILITY = YES; 305 | GCC_C_LANGUAGE_STANDARD = gnu99; 306 | GCC_DYNAMIC_NO_PIC = NO; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_OPTIMIZATION_LEVEL = 0; 309 | GCC_PREPROCESSOR_DEFINITIONS = ( 310 | "DEBUG=1", 311 | "$(inherited)", 312 | ); 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 320 | MTL_ENABLE_DEBUG_INFO = YES; 321 | ONLY_ACTIVE_ARCH = YES; 322 | SDKROOT = iphoneos; 323 | }; 324 | name = Debug; 325 | }; 326 | 37DD22DF1BB243AC00D31310 /* Release */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | ALWAYS_SEARCH_USER_PATHS = NO; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INT_CONVERSION = YES; 340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 341 | CLANG_WARN_UNREACHABLE_CODE = YES; 342 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 343 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 344 | COPY_PHASE_STRIP = NO; 345 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 346 | ENABLE_NS_ASSERTIONS = NO; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | GCC_C_LANGUAGE_STANDARD = gnu99; 349 | GCC_NO_COMMON_BLOCKS = YES; 350 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 351 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 352 | GCC_WARN_UNDECLARED_SELECTOR = YES; 353 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 354 | GCC_WARN_UNUSED_FUNCTION = YES; 355 | GCC_WARN_UNUSED_VARIABLE = YES; 356 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 357 | MTL_ENABLE_DEBUG_INFO = NO; 358 | SDKROOT = iphoneos; 359 | VALIDATE_PRODUCT = YES; 360 | }; 361 | name = Release; 362 | }; 363 | 37DD22E11BB243AC00D31310 /* Debug */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 367 | INFOPLIST_FILE = XBSettingControllerDemo/Info.plist; 368 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = XB.XBSettingControllerDemo; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | }; 373 | name = Debug; 374 | }; 375 | 37DD22E21BB243AC00D31310 /* Release */ = { 376 | isa = XCBuildConfiguration; 377 | buildSettings = { 378 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 379 | INFOPLIST_FILE = XBSettingControllerDemo/Info.plist; 380 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 382 | PRODUCT_BUNDLE_IDENTIFIER = XB.XBSettingControllerDemo; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | }; 385 | name = Release; 386 | }; 387 | /* End XCBuildConfiguration section */ 388 | 389 | /* Begin XCConfigurationList section */ 390 | 37DD22C41BB243AC00D31310 /* Build configuration list for PBXProject "XBSettingControllerDemo" */ = { 391 | isa = XCConfigurationList; 392 | buildConfigurations = ( 393 | 37DD22DE1BB243AC00D31310 /* Debug */, 394 | 37DD22DF1BB243AC00D31310 /* Release */, 395 | ); 396 | defaultConfigurationIsVisible = 0; 397 | defaultConfigurationName = Release; 398 | }; 399 | 37DD22E01BB243AC00D31310 /* Build configuration list for PBXNativeTarget "XBSettingControllerDemo" */ = { 400 | isa = XCConfigurationList; 401 | buildConfigurations = ( 402 | 37DD22E11BB243AC00D31310 /* Debug */, 403 | 37DD22E21BB243AC00D31310 /* Release */, 404 | ); 405 | defaultConfigurationIsVisible = 0; 406 | }; 407 | /* End XCConfigurationList section */ 408 | }; 409 | rootObject = 37DD22C11BB243AC00D31310 /* Project object */; 410 | } 411 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/DemoMeController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoMeController.h 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DemoMeController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/DemoMeController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoMeController.m 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import "DemoMeController.h" 10 | #import "XBMeHeaderView.h" 11 | #import "XBConst.h" 12 | #import "XBSettingCell.h" 13 | #import "XBSettingItemModel.h" 14 | #import "XBSettingSectionModel.h" 15 | #import "DemoSettingController.h" 16 | @interface DemoMeController () 17 | @property (nonatomic,strong) XBMeHeaderView *header; 18 | 19 | 20 | @property (nonatomic,strong) NSArray *sectionArray; /**< section模型数组*/ 21 | @end 22 | 23 | @implementation DemoMeController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | 28 | self.view.backgroundColor = XBMakeColorWithRGB(234, 234, 234, 1); 29 | self.tableView.backgroundColor = [UIColor whiteColor]; 30 | [self setupSections]; 31 | 32 | XBMeHeaderView *header = [[[NSBundle mainBundle]loadNibNamed:@"XBMeHeaderView" owner:nil options:nil] firstObject]; 33 | self.header = header; 34 | self.tableView.tableHeaderView = header; 35 | } 36 | 37 | - (void)setupSections 38 | { 39 | 40 | //************************************section1 41 | XBSettingItemModel *item1 = [[XBSettingItemModel alloc]init]; 42 | item1.funcName = @"我的任务1"; 43 | item1.executeCode = ^{ 44 | NSLog(@"我的任务1"); 45 | }; 46 | item1.img = [UIImage imageNamed:@"icon-list01"]; 47 | item1.detailText = @"做任务赢大奖"; 48 | item1.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 49 | 50 | 51 | XBSettingItemModel *item2 = [[XBSettingItemModel alloc]init]; 52 | item2.funcName = @"我的任务2"; 53 | item2.img = [UIImage imageNamed:@"icon-list01"]; 54 | item2.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 55 | 56 | XBSettingItemModel *item3 = [[XBSettingItemModel alloc]init]; 57 | item3.funcName = @"我的任务3"; 58 | item3.img = [UIImage imageNamed:@"icon-list01"]; 59 | item3.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 60 | 61 | XBSettingItemModel *item4 = [[XBSettingItemModel alloc]init]; 62 | item4.funcName = @"我的任务4"; 63 | item4.img = [UIImage imageNamed:@"icon-list01"]; 64 | item4.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 65 | 66 | XBSettingSectionModel *section1 = [[XBSettingSectionModel alloc]init]; 67 | section1.sectionHeaderHeight = 18; 68 | section1.itemArray = @[item1,item2,item3,item4]; 69 | 70 | XBSettingItemModel *item5 = [[XBSettingItemModel alloc]init]; 71 | item5.funcName = @"充值中心"; 72 | item5.img = [UIImage imageNamed:@"icon-list01"]; 73 | item5.executeCode = ^{ 74 | NSLog(@"充值中心"); 75 | }; 76 | item5.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 77 | 78 | XBSettingItemModel *item6 = [[XBSettingItemModel alloc]init]; 79 | item6.funcName = @"设置"; 80 | item6.img = [UIImage imageNamed:@"icon-list01"]; 81 | item6.executeCode = ^{ 82 | 83 | }; 84 | item6.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 85 | 86 | XBSettingSectionModel *section2 = [[XBSettingSectionModel alloc]init]; 87 | section2.sectionHeaderHeight = 18; 88 | section2.itemArray = @[item5,item6]; 89 | 90 | self.sectionArray = @[section1,section2]; 91 | } 92 | 93 | 94 | #pragma mark - Table view data source 95 | 96 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 97 | 98 | return self.sectionArray.count; 99 | } 100 | 101 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 102 | 103 | XBSettingSectionModel *sectionModel = self.sectionArray[section]; 104 | return sectionModel.itemArray.count;} 105 | 106 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 107 | { 108 | static NSString *identifier = @"setting"; 109 | XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section]; 110 | XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row]; 111 | 112 | XBSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 113 | if (!cell) { 114 | cell = [[XBSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 115 | } 116 | cell.item = itemModel; 117 | return cell; 118 | } 119 | 120 | #pragma mark - Table view delegate 121 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 122 | { 123 | XBSettingSectionModel *sectionModel = self.sectionArray[section]; 124 | return sectionModel.sectionHeaderHeight; 125 | } 126 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 127 | { 128 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 129 | XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section]; 130 | XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row]; 131 | if (itemModel.executeCode) { 132 | itemModel.executeCode(); 133 | } 134 | } 135 | //uitableview处理section的不悬浮,禁止section停留的方法,主要是这段代码 136 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 137 | XBSettingSectionModel *sectionModel = [self.sectionArray firstObject]; 138 | CGFloat sectionHeaderHeight = sectionModel.sectionHeaderHeight; 139 | 140 | if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) { 141 | scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); 142 | } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { 143 | scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); 144 | } 145 | } 146 | @end 147 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/DemoSettingController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoSettingController.h 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DemoSettingController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/DemoSettingController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoSettingController.m 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import "DemoSettingController.h" 10 | #import "XBConst.h" 11 | #import "XBSettingCell.h" 12 | #import "XBSettingItemModel.h" 13 | #import "XBSettingSectionModel.h" 14 | @interface DemoSettingController () 15 | @property (nonatomic,strong) NSArray *sectionArray; /**< section模型数组*/ 16 | 17 | @end 18 | 19 | @implementation DemoSettingController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.view.backgroundColor = XBMakeColorWithRGB(234, 234, 234, 1); 24 | self.tableView.backgroundColor = [UIColor whiteColor]; 25 | [self setupSections]; 26 | } 27 | 28 | - (void)showAlert:(NSString *)title 29 | { 30 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"点击了" message:title delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; 31 | [alert show]; 32 | } 33 | 34 | #pragma - mark setup 35 | - (void)setupSections 36 | { 37 | //************************************section1 38 | XBSettingItemModel *item1 = [[XBSettingItemModel alloc]init]; 39 | item1.funcName = @"我的余额"; 40 | item1.executeCode = ^{ 41 | NSLog(@"我的余额"); 42 | [self showAlert:@"我的余额"]; 43 | }; 44 | item1.detailText = @"做任务赢大奖"; 45 | item1.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 46 | 47 | XBSettingItemModel *item2 = [[XBSettingItemModel alloc]init]; 48 | item2.funcName = @"修改密码"; 49 | item2.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 50 | 51 | XBSettingSectionModel *section1 = [[XBSettingSectionModel alloc]init]; 52 | section1.sectionHeaderHeight = 18; 53 | section1.itemArray = @[item1,item2]; 54 | 55 | //************************************section2 56 | XBSettingItemModel *item3 = [[XBSettingItemModel alloc]init]; 57 | item3.funcName = @"推送提醒"; 58 | item3.accessoryType = XBSettingAccessoryTypeSwitch; 59 | item3.switchValueChanged = ^(BOOL isOn) 60 | { 61 | NSLog(@"推送提醒开关状态===%@",isOn?@"open":@"close"); 62 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"推送提醒" message:isOn?@"open":@"close" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; 63 | [alert show]; 64 | }; 65 | 66 | XBSettingItemModel *item4 = [[XBSettingItemModel alloc]init]; 67 | item4.funcName = @"给我们打分"; 68 | item4.detailImage = [UIImage imageNamed:@"icon-new"]; 69 | item4.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 70 | 71 | XBSettingItemModel *item5 = [[XBSettingItemModel alloc]init]; 72 | item5.funcName = @"意见反馈"; 73 | item5.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 74 | 75 | XBSettingSectionModel *section2 = [[XBSettingSectionModel alloc]init]; 76 | section2.sectionHeaderHeight = 18; 77 | section2.itemArray = @[item3,item4,item5]; 78 | 79 | 80 | //************************************section3 81 | XBSettingItemModel *item6 = [[XBSettingItemModel alloc]init]; 82 | item6.funcName = @"关于我们"; 83 | item6.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 84 | 85 | XBSettingItemModel *item7 = [[XBSettingItemModel alloc]init]; 86 | item7.funcName = @"帮助中心"; 87 | item7.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 88 | 89 | XBSettingItemModel *item8 = [[XBSettingItemModel alloc]init]; 90 | item8.funcName = @"清除缓存"; 91 | item8.accessoryType = XBSettingAccessoryTypeDisclosureIndicator; 92 | 93 | XBSettingSectionModel *section3 = [[XBSettingSectionModel alloc]init]; 94 | section3.sectionHeaderHeight = 18; 95 | section3.itemArray = @[item6,item7,item8]; 96 | 97 | self.sectionArray = @[section1,section2,section3]; 98 | } 99 | 100 | #pragma mark - Table view data source 101 | 102 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 103 | return self.sectionArray.count; 104 | } 105 | 106 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 107 | XBSettingSectionModel *sectionModel = self.sectionArray[section]; 108 | return sectionModel.itemArray.count; 109 | } 110 | 111 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 112 | { 113 | static NSString *identifier = @"setting"; 114 | XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section]; 115 | XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row]; 116 | 117 | XBSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 118 | if (!cell) { 119 | cell = [[XBSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 120 | } 121 | cell.item = itemModel; 122 | return cell; 123 | } 124 | 125 | #pragma - mark UITableViewDelegate 126 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 127 | { 128 | XBSettingSectionModel *sectionModel = self.sectionArray[section]; 129 | return sectionModel.sectionHeaderHeight; 130 | } 131 | 132 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 133 | { 134 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 135 | XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section]; 136 | XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row]; 137 | if (itemModel.executeCode) { 138 | itemModel.executeCode(); 139 | } 140 | } 141 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 142 | XBSettingSectionModel *sectionModel = [self.sectionArray firstObject]; 143 | CGFloat sectionHeaderHeight = sectionModel.sectionHeaderHeight; 144 | 145 | if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) { 146 | scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); 147 | } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { 148 | scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); 149 | } 150 | } 151 | 152 | @end 153 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-arrow1@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-arrow1@2x.png -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-list01@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-list01@2x.png -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-new@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/changjianfeishui/XBSettingController/e291e295936d31b427fba5fd1ddf5283cf1edb08/XBSettingControllerDemo/XBSettingControllerDemo/Imges/icon-new@2x.png -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Category/UIView+XBExtension.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Extension.h 3 | // 4 | // 5 | /// 6 | 7 | #import 8 | 9 | @interface UIView (XBExtension) 10 | @property (nonatomic, assign) CGFloat x; 11 | @property (nonatomic, assign) CGFloat y; 12 | @property (nonatomic, assign) CGFloat centerX; 13 | @property (nonatomic, assign) CGFloat centerY; 14 | @property (nonatomic, assign) CGFloat width; 15 | @property (nonatomic, assign) CGFloat height; 16 | @property (nonatomic, assign) CGSize size; 17 | @end 18 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Category/UIView+XBExtension.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Extension.m 3 | // 4 | 5 | #import "UIView+XBExtension.h" 6 | 7 | @implementation UIView (XBExtension) 8 | 9 | - (void)setX:(CGFloat)x 10 | { 11 | CGRect frame = self.frame; 12 | frame.origin.x = x; 13 | self.frame = frame; 14 | } 15 | 16 | - (CGFloat)x 17 | { 18 | return self.frame.origin.x; 19 | } 20 | 21 | - (void)setY:(CGFloat)y 22 | { 23 | CGRect frame = self.frame; 24 | frame.origin.y = y; 25 | self.frame = frame; 26 | } 27 | 28 | - (CGFloat)y 29 | { 30 | return self.frame.origin.y; 31 | } 32 | 33 | - (void)setCenterX:(CGFloat)centerX 34 | { 35 | CGPoint center = self.center; 36 | center.x = centerX; 37 | self.center = center; 38 | } 39 | 40 | - (CGFloat)centerX 41 | { 42 | return self.center.x; 43 | } 44 | 45 | - (void)setCenterY:(CGFloat)centerY 46 | { 47 | CGPoint center = self.center; 48 | center.y = centerY; 49 | self.center = center; 50 | } 51 | 52 | - (CGFloat)centerY 53 | { 54 | return self.center.y; 55 | } 56 | 57 | - (void)setWidth:(CGFloat)width 58 | { 59 | CGRect frame = self.frame; 60 | frame.size.width = width; 61 | self.frame = frame; 62 | } 63 | 64 | - (CGFloat)width 65 | { 66 | return self.frame.size.width; 67 | } 68 | 69 | - (void)setHeight:(CGFloat)height 70 | { 71 | CGRect frame = self.frame; 72 | frame.size.height = height; 73 | self.frame = frame; 74 | } 75 | 76 | - (CGFloat)height 77 | { 78 | return self.frame.size.height; 79 | } 80 | 81 | - (void)setSize:(CGSize)size 82 | { 83 | // self.width = size.width; 84 | // self.height = size.height; 85 | CGRect frame = self.frame; 86 | frame.size = size; 87 | self.frame = frame; 88 | } 89 | 90 | - (CGSize)size 91 | { 92 | return self.frame.size; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Const/XBConst.h: -------------------------------------------------------------------------------- 1 | // 2 | // XBConst.h 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #ifndef XBConst_h 10 | #define XBConst_h 11 | 12 | 13 | #define XBMakeColorWithRGB(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] 14 | //获取屏幕尺寸 15 | #define XBScreenWidth [UIScreen mainScreen].bounds.size.width 16 | #define XBScreenHeight [UIScreen mainScreen].bounds.size.height 17 | #define XBScreenBounds [UIScreen mainScreen].bounds 18 | 19 | 20 | //功能图片到左边界的距离 21 | #define XBFuncImgToLeftGap 15 22 | 23 | //功能名称字体 24 | #define XBFuncLabelFont 14 25 | 26 | //功能名称到功能图片的距离,当功能图片funcImg不存在时,等于到左边界的距离 27 | #define XBFuncLabelToFuncImgGap 15 28 | 29 | //指示箭头或开关到右边界的距离 30 | #define XBIndicatorToRightGap 15 31 | 32 | //详情文字字体 33 | #define XBDetailLabelFont 12 34 | 35 | //详情到指示箭头或开关的距离 36 | #define XBDetailViewToIndicatorGap 13 37 | 38 | #endif /* XBConst_h */ 39 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Model/XBSettingItemModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingItemModel.h 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | typedef NS_ENUM(NSInteger, XBSettingAccessoryType) { 12 | XBSettingAccessoryTypeNone, // don't show any accessory view 13 | XBSettingAccessoryTypeDisclosureIndicator, // the same with system DisclosureIndicator 14 | XBSettingAccessoryTypeSwitch, // swithch 15 | }; 16 | 17 | 18 | 19 | @interface XBSettingItemModel : NSObject 20 | @property (nonatomic,copy) NSString *funcName; /**< 功能名称*/ 21 | @property (nonatomic,strong) UIImage *img; /**< 功能图片 */ 22 | @property (nonatomic,copy) NSString *detailText; /**< 更多信息-提示文字 */ 23 | @property (nonatomic,strong) UIImage *detailImage; /**< 更多信息-提示图片 */ 24 | 25 | 26 | @property (nonatomic,assign) XBSettingAccessoryType accessoryType; /**< accessory */ 27 | @property (nonatomic,copy) void (^executeCode)(); /**< 点击item要执行的代码*/ 28 | @property (nonatomic,copy) void (^switchValueChanged)(BOOL isOn); /**< XBSettingAccessoryTypeSwitch下开关变化 */ 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Model/XBSettingItemModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingItemModel.m 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import "XBSettingItemModel.h" 10 | 11 | @implementation XBSettingItemModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Model/XBSettingSectionModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingSectionModel.h 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | @interface XBSettingSectionModel : NSObject 12 | @property (nonatomic,copy) NSString *sectionHeaderName; /**< 传空表示分组无名称*/ 13 | 14 | @property (nonatomic,assign) CGFloat sectionHeaderHeight; /**< 分组header高度*/ 15 | 16 | @property (nonatomic,strong) NSArray *itemArray; /**< item模型数组*/ 17 | 18 | @property (nonatomic,strong) UIColor *sectionHeaderBgColor; /**< 背景色*/ 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/Model/XBSettingSectionModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingSectionModel.m 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import "XBSettingSectionModel.h" 10 | 11 | @implementation XBSettingSectionModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/View/XBMeHeaderView.h: -------------------------------------------------------------------------------- 1 | // 2 | // XBMeHeaderView.h 3 | // xiu8iOS 4 | // 5 | // Created by Scarecrow on 15/9/19. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, XBMeHeaderViewButtonType) { 12 | XBMeHeaderViewButtonTypeLogin, 13 | XBMeHeaderViewButtonTypeRegister, 14 | XBMeHeaderViewButtonTypeHistory, 15 | XBMeHeaderViewButtonTypeAttention, 16 | XBMeHeaderViewButtonTypeGuard 17 | }; 18 | 19 | 20 | @protocol XBMeHeaderViewDelegate 21 | 22 | - (void)XBMeHeaderViewBtnClicked:(XBMeHeaderViewButtonType)type; 23 | 24 | @end 25 | 26 | @interface XBMeHeaderView : UIView 27 | @property (nonatomic,weak) id delegate; 28 | 29 | - (void)loginStateChanged:(BOOL)loginState; 30 | @end 31 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/View/XBMeHeaderView.m: -------------------------------------------------------------------------------- 1 | // 2 | // XBMeHeaderView.m 3 | // xiu8iOS 4 | // 5 | // Created by Scarecrow on 15/9/19. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import "XBMeHeaderView.h" 10 | @interface XBMeHeaderView() 11 | @property (weak, nonatomic) IBOutlet UIView *circleBg; 12 | @property (weak, nonatomic) IBOutlet UIImageView *header; 13 | 14 | @property (weak, nonatomic) IBOutlet UIButton *loginBtn; 15 | 16 | @property (weak, nonatomic) IBOutlet UIView *alreadyLoginView; 17 | 18 | @property (weak, nonatomic) IBOutlet UIView *noLoginView; 19 | 20 | @end 21 | @implementation XBMeHeaderView 22 | 23 | - (void)awakeFromNib 24 | { 25 | [self setupHeaderCircle]; 26 | } 27 | 28 | - (void)loginStateChanged:(BOOL)loginState 29 | { 30 | self.noLoginView.hidden = loginState; 31 | self.alreadyLoginView.hidden = !loginState; 32 | } 33 | 34 | - (IBAction)loginBtnDidClicked:(UIButton *)sender { 35 | if ([self.delegate respondsToSelector:@selector(XBMeHeaderViewBtnClicked:)]) { 36 | [self.delegate XBMeHeaderViewBtnClicked:XBMeHeaderViewButtonTypeLogin]; 37 | } 38 | } 39 | 40 | - (IBAction)registerBtnClicked:(UIButton *)sender { 41 | if ([self.delegate respondsToSelector:@selector(XBMeHeaderViewBtnClicked:)]) { 42 | [self.delegate XBMeHeaderViewBtnClicked:XBMeHeaderViewButtonTypeRegister]; 43 | } 44 | } 45 | 46 | - (IBAction)attentionBtnDidClicked:(UIButton *)sender { 47 | if ([self.delegate respondsToSelector:@selector(XBMeHeaderViewBtnClicked:)]) { 48 | [self.delegate XBMeHeaderViewBtnClicked:XBMeHeaderViewButtonTypeAttention]; 49 | } 50 | } 51 | 52 | - (IBAction)historyBtnDidClicked:(UIButton *)sender { 53 | if ([self.delegate respondsToSelector:@selector(XBMeHeaderViewBtnClicked:)]) { 54 | [self.delegate XBMeHeaderViewBtnClicked:XBMeHeaderViewButtonTypeHistory]; 55 | } 56 | } 57 | 58 | - (IBAction)guardBtnDidClicked:(UIButton *)sender { 59 | if ([self.delegate respondsToSelector:@selector(XBMeHeaderViewBtnClicked:)]) { 60 | [self.delegate XBMeHeaderViewBtnClicked:XBMeHeaderViewButtonTypeGuard]; 61 | } 62 | } 63 | 64 | 65 | 66 | - (void)setupHeaderCircle 67 | { 68 | // self.circleBg.layer.cornerRadius = self.circleBg.height * 0.5; 69 | // self.header.layer.cornerRadius = self.header.width * 0.5; 70 | // self.header.clipsToBounds = YES; 71 | // self.circleBg.clipsToBounds = YES; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/View/XBMeHeaderView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/View/XBSettingCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingCell.h 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import 10 | @class XBSettingItemModel; 11 | @interface XBSettingCell : UITableViewCell 12 | @property (nonatomic,strong) XBSettingItemModel *item; /**< item data*/ 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/XBSettingController/View/XBSettingCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // XBSettingCell.m 3 | // xiu8iOS 4 | // 5 | // Created by XB on 15/9/18. 6 | // Copyright (c) 2015年 xiu8. All rights reserved. 7 | // 8 | 9 | #import "XBSettingCell.h" 10 | #import "XBSettingItemModel.h" 11 | #import "UIView+XBExtension.h" 12 | #import "XBConst.h" 13 | @interface XBSettingCell() 14 | @property (strong, nonatomic) UILabel *funcNameLabel; 15 | @property (nonatomic,strong) UIImageView *imgView; 16 | 17 | @property (nonatomic,strong) UIImageView *indicator; 18 | 19 | @property (nonatomic,strong) UISwitch *aswitch; 20 | 21 | @property (nonatomic,strong) UILabel *detailLabel; 22 | 23 | @property (nonatomic,strong) UIImageView *detailImageView; 24 | 25 | 26 | 27 | @end 28 | @implementation XBSettingCell 29 | 30 | - (void)setItem:(XBSettingItemModel *)item 31 | { 32 | _item = item; 33 | [self updateUI]; 34 | 35 | } 36 | 37 | - (void)updateUI 38 | { 39 | [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 40 | 41 | //如果有图片 42 | if (self.item.img) { 43 | [self setupImgView]; 44 | } 45 | //功能名称 46 | if (self.item.funcName) { 47 | [self setupFuncLabel]; 48 | } 49 | 50 | //accessoryType 51 | if (self.item.accessoryType) { 52 | [self setupAccessoryType]; 53 | } 54 | //detailView 55 | if (self.item.detailText) { 56 | [self setupDetailText]; 57 | } 58 | if (self.item.detailImage) { 59 | [self setupDetailImage]; 60 | } 61 | 62 | //bottomLine 63 | UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, self.height - 1, XBScreenWidth, 1)]; 64 | line.backgroundColor = XBMakeColorWithRGB(234, 234, 234, 1); 65 | [self.contentView addSubview:line]; 66 | 67 | } 68 | 69 | -(void)setupDetailImage 70 | { 71 | self.detailImageView = [[UIImageView alloc]initWithImage:self.item.detailImage]; 72 | self.detailImageView.centerY = self.contentView.centerY; 73 | switch (self.item.accessoryType) { 74 | case XBSettingAccessoryTypeNone: 75 | self.detailImageView.x = XBScreenWidth - self.detailImageView.width - XBDetailViewToIndicatorGap - 2; 76 | break; 77 | case XBSettingAccessoryTypeDisclosureIndicator: 78 | self.detailImageView.x = self.indicator.x - self.detailImageView.width - XBDetailViewToIndicatorGap; 79 | break; 80 | case XBSettingAccessoryTypeSwitch: 81 | self.detailImageView.x = self.aswitch.x - self.detailImageView.width - XBDetailViewToIndicatorGap; 82 | break; 83 | default: 84 | break; 85 | } 86 | [self.contentView addSubview:self.detailImageView]; 87 | } 88 | 89 | - (void)setupDetailText 90 | { 91 | self.detailLabel = [[UILabel alloc]init]; 92 | self.detailLabel.text = self.item.detailText; 93 | self.detailLabel.textColor = XBMakeColorWithRGB(142, 142, 142, 1); 94 | self.detailLabel.font = [UIFont systemFontOfSize:XBDetailLabelFont]; 95 | self.detailLabel.size = [self sizeForTitle:self.item.detailText withFont:self.detailLabel.font]; 96 | self.detailLabel.centerY = self.contentView.centerY; 97 | 98 | switch (self.item.accessoryType) { 99 | case XBSettingAccessoryTypeNone: 100 | self.detailLabel.x = XBScreenWidth - self.detailLabel.width - XBDetailViewToIndicatorGap - 2; 101 | break; 102 | case XBSettingAccessoryTypeDisclosureIndicator: 103 | self.detailLabel.x = self.indicator.x - self.detailLabel.width - XBDetailViewToIndicatorGap; 104 | break; 105 | case XBSettingAccessoryTypeSwitch: 106 | self.detailLabel.x = self.aswitch.x - self.detailLabel.width - XBDetailViewToIndicatorGap; 107 | break; 108 | default: 109 | break; 110 | } 111 | 112 | [self.contentView addSubview:self.detailLabel]; 113 | } 114 | 115 | 116 | - (void)setupAccessoryType 117 | { 118 | switch (self.item.accessoryType) { 119 | case XBSettingAccessoryTypeNone: 120 | break; 121 | case XBSettingAccessoryTypeDisclosureIndicator: 122 | [self setupIndicator]; 123 | break; 124 | case XBSettingAccessoryTypeSwitch: 125 | [self setupSwitch]; 126 | break; 127 | default: 128 | break; 129 | } 130 | } 131 | 132 | - (void)setupSwitch 133 | { 134 | [self.contentView addSubview:self.aswitch]; 135 | } 136 | 137 | - (void)setupIndicator 138 | { 139 | [self.contentView addSubview:self.indicator]; 140 | 141 | } 142 | 143 | - (void)setupImgView 144 | { 145 | self.imgView = [[UIImageView alloc]initWithImage:self.item.img]; 146 | self.imgView.x = XBFuncImgToLeftGap; 147 | self.imgView.centerY = self.contentView.centerY; 148 | self.imgView.centerY = self.contentView.centerY; 149 | [self.contentView addSubview:self.imgView]; 150 | } 151 | 152 | - (void)setupFuncLabel 153 | { 154 | self.funcNameLabel = [[UILabel alloc]init]; 155 | self.funcNameLabel.text = self.item.funcName; 156 | self.funcNameLabel.textColor = XBMakeColorWithRGB(51, 51, 51, 1); 157 | self.funcNameLabel.font = [UIFont systemFontOfSize:XBFuncLabelFont]; 158 | self.funcNameLabel.size = [self sizeForTitle:self.item.funcName withFont:self.funcNameLabel.font]; 159 | self.funcNameLabel.centerY = self.contentView.centerY; 160 | self.funcNameLabel.x = CGRectGetMaxX(self.imgView.frame) + XBFuncLabelToFuncImgGap; 161 | [self.contentView addSubview:self.funcNameLabel]; 162 | } 163 | 164 | - (CGSize)sizeForTitle:(NSString *)title withFont:(UIFont *)font 165 | { 166 | CGRect titleRect = [title boundingRectWithSize:CGSizeMake(FLT_MAX, FLT_MAX) 167 | options:NSStringDrawingUsesLineFragmentOrigin 168 | attributes:@{NSFontAttributeName : font} 169 | context:nil]; 170 | 171 | return CGSizeMake(titleRect.size.width, 172 | titleRect.size.height); 173 | } 174 | 175 | - (UIImageView *)indicator 176 | { 177 | if (!_indicator) { 178 | _indicator = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon-arrow1"]]; 179 | _indicator.centerY = self.contentView.centerY; 180 | _indicator.x = XBScreenWidth - _indicator.width - XBIndicatorToRightGap; 181 | } 182 | return _indicator; 183 | } 184 | 185 | - (UISwitch *)aswitch 186 | { 187 | if (!_aswitch) { 188 | _aswitch = [[UISwitch alloc]init]; 189 | _aswitch.centerY = self.contentView.centerY; 190 | _aswitch.x = XBScreenWidth - _aswitch.width - XBIndicatorToRightGap; 191 | [_aswitch addTarget:self action:@selector(switchTouched:) forControlEvents:UIControlEventValueChanged]; 192 | } 193 | return _aswitch; 194 | } 195 | 196 | - (void)switchTouched:(UISwitch *)sw 197 | { 198 | __weak typeof(self) weakSelf = self; 199 | self.item.switchValueChanged(weakSelf.aswitch.isOn); 200 | } 201 | 202 | @end 203 | -------------------------------------------------------------------------------- /XBSettingControllerDemo/XBSettingControllerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // XBSettingControllerDemo 4 | // 5 | // Created by XB on 15/9/23. 6 | // Copyright © 2015年 XB. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------