Skip to content

Commit

Permalink
Improved field layout of MultiValue, TitleValue and Toggle fields;
Browse files Browse the repository at this point in the history
fixed display issue with tableView separator
  • Loading branch information
Ortwin Gentz committed Mar 5, 2010
1 parent 76de594 commit 03d6407
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 33 deletions.
24 changes: 4 additions & 20 deletions InAppSettingsKit/Controllers/IASKAppSettingsViewController.m
Expand Up @@ -20,6 +20,7 @@
#import "IASKPSToggleSwitchSpecifierViewCell.h"
#import "IASKPSSliderSpecifierViewCell.h"
#import "IASKPSTextFieldSpecifierViewCell.h"
#import "IASKPSTitleValueSpecifierViewCell.h"
#import "IASKSwitch.h"
#import "IASKSlider.h"
#import "IASKSpecifier.h"
Expand Down Expand Up @@ -302,25 +303,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
else if ([[specifier type] isEqualToString:kIASKPSMultiValueSpecifier]) {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSMultiValueSpecifier] autorelease];
UITableViewCell *cell = [[[IASKPSTitleValueSpecifierViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSMultiValueSpecifier] autorelease];
[[cell textLabel] setText:[specifier title]];
[[cell detailTextLabel] setText:[[specifier titleForCurrentValue:[[NSUserDefaults standardUserDefaults] objectForKey:key] != nil ?
[[NSUserDefaults standardUserDefaults] objectForKey:key] : [specifier defaultValue]] description]];

// left align the value if the title is empty
if (!specifier.title.length) {
cell.textLabel.text = cell.detailTextLabel.text;
cell.textLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
cell.textLabel.textColor = cell.detailTextLabel.textColor;
cell.detailTextLabel.text = nil;
}

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

return cell;
}
else if ([[specifier type] isEqualToString:kIASKPSTitleValueSpecifier]) {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSTitleValueSpecifier] autorelease];
UITableViewCell *cell = [[[IASKPSTitleValueSpecifierViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSTitleValueSpecifier] autorelease];
cell.textLabel.text = [specifier title];
id value = [[NSUserDefaults standardUserDefaults] objectForKey:key] ? : [specifier defaultValue];

Expand All @@ -333,15 +326,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

cell.detailTextLabel.text = stringValue;

// left align the value if the title is empty
if (!specifier.title.length) {
cell.textLabel.text = cell.detailTextLabel.text;
cell.textLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
cell.textLabel.textColor = cell.detailTextLabel.textColor;
cell.detailTextLabel.text = nil;
}
cell.textLabel.adjustsFontSizeToFitWidth = YES;

[cell setUserInteractionEnabled:NO];
[cell setAccessoryType:UITableViewCellAccessoryNone];
return cell;
Expand Down Expand Up @@ -398,7 +382,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
else if ([[specifier type] isEqualToString:kIASKPSChildPaneSpecifier]) {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSChildPaneSpecifier] autorelease];
UITableViewCell *cell = [[[IASKPSTitleValueSpecifierViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kIASKPSChildPaneSpecifier] autorelease];
[[cell textLabel] setText:[specifier title]];
//NSLog(@"[specifier file]: %@", [specifier file]);
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
Expand Down
7 changes: 6 additions & 1 deletion InAppSettingsKit/Models/IASKSettingsReader.h
Expand Up @@ -70,8 +70,13 @@
#define kIASKSliderOneImageWidth 246

#define kIASKTableWidth 320
#define kIASKSpacing 9
#define kIASKSpacing 5
#define kIASKMinLabelWidth 97
#define kIASKMinValueWidth 35
#define kIASKPaddingLeft 9
#define kIASKPaddingRight 10

#define kIASKLabelFontSize 17

@class IASKSpecifier;

Expand Down
14 changes: 14 additions & 0 deletions InAppSettingsKit/Views/IASKPSTitleValueSpecifierViewCell.h
@@ -0,0 +1,14 @@
//
// IASKPSTitleValueSpecifierViewCell.h
// InAppSettingsKitSampleApp
//
// Created by Ortwin Gentz on 04.03.10.
// Copyright 2010 FutureTap. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface IASKPSTitleValueSpecifierViewCell : UITableViewCell

@end
48 changes: 48 additions & 0 deletions InAppSettingsKit/Views/IASKPSTitleValueSpecifierViewCell.m
@@ -0,0 +1,48 @@
//
// IASKPSTitleValueSpecifierViewCell.m
// InAppSettingsKitSampleApp
//
// Created by Ortwin Gentz on 04.03.10.
// Copyright 2010 FutureTap. All rights reserved.
//

#import "IASKPSTitleValueSpecifierViewCell.h"
#import "IASKSettingsReader.h"


@implementation IASKPSTitleValueSpecifierViewCell

- (void)layoutSubviews {
// left align the value if the title is empty
if (!self.textLabel.text.length) {
self.textLabel.text = self.detailTextLabel.text;
self.detailTextLabel.text = nil;
if ([self.reuseIdentifier isEqualToString:kIASKPSMultiValueSpecifier]) {
self.textLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
self.textLabel.textColor = self.detailTextLabel.textColor;
}
}
[super layoutSubviews];

CGFloat viewWidth = [self.textLabel superview].frame.size.width;

// set the left title label frame
CGFloat labelWidth = [self.textLabel sizeThatFits:CGSizeZero].width;
labelWidth = MIN(labelWidth, viewWidth - kIASKMinValueWidth - kIASKPaddingLeft - kIASKSpacing -kIASKPaddingRight);
CGRect labelFrame = self.textLabel.frame;
labelFrame.origin.x = kIASKPaddingLeft;
labelFrame.size.width = labelWidth;
labelFrame.size.height -= 2;
self.textLabel.frame = labelFrame;

// set the right value label frame
if (self.detailTextLabel.text.length) {
CGRect valueFrame = self.detailTextLabel.frame;
valueFrame.origin.x = kIASKPaddingLeft + labelWidth + kIASKSpacing;
valueFrame.size.width = viewWidth - valueFrame.origin.x - kIASKPaddingRight;
valueFrame.size.height -= 2;
self.detailTextLabel.frame = valueFrame;
}
}

@end
5 changes: 3 additions & 2 deletions InAppSettingsKit/Xibs/IASKPSSliderSpecifierViewCell.xib
Expand Up @@ -37,7 +37,7 @@
</object>
<object class="IBUITableViewCell" id="699910302">
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<int key="NSvFlags">290</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIView" id="833157797">
Expand All @@ -59,7 +59,7 @@
</object>
<object class="IBUIImageView" id="343121076">
<reference key="NSNextResponder" ref="833157797"/>
<int key="NSvFlags">292</int>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{278, 13}, {21, 21}}</string>
<reference key="NSSuperview" ref="833157797"/>
<bool key="IBUIOpaque">NO</bool>
Expand Down Expand Up @@ -96,6 +96,7 @@
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUISeparatorStyle">1</int>
<reference key="IBUIContentView" ref="833157797"/>
Expand Down
9 changes: 5 additions & 4 deletions InAppSettingsKit/Xibs/IASKPSTextFieldSpecifierViewCell.xib
Expand Up @@ -37,7 +37,7 @@
</object>
<object class="IBUITableViewCell" id="639928991">
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<int key="NSvFlags">290</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIView" id="642554623">
Expand Down Expand Up @@ -90,7 +90,7 @@
<object class="IBUITextInputTraits" key="IBUITextInputTraits"/>
</object>
</object>
<string key="NSFrameSize">{320, 43}</string>
<string key="NSFrameSize">{320, 44}</string>
<reference key="NSSuperview" ref="639928991"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
Expand All @@ -102,12 +102,13 @@
<bool key="IBUIMultipleTouchEnabled">YES</bool>
</object>
</object>
<string key="NSFrameSize">{320, 44}</string>
<string key="NSFrameSize">{320, 45}</string>
<reference key="NSSuperview"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISelectionStyle">0</int>
Expand Down Expand Up @@ -193,7 +194,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIResponder</string>
<string>IASKPSTextFieldSpecifierViewCell</string>
<string>{{105, 513}, {320, 44}}</string>
<string>{{105, 512}, {320, 45}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>IASKTextField</string>
Expand Down
11 changes: 6 additions & 5 deletions InAppSettingsKit/Xibs/IASKPSToggleSwitchSpecifierViewCell.xib
Expand Up @@ -37,7 +37,7 @@
</object>
<object class="IBUITableViewCell" id="507262743">
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<int key="NSvFlags">290</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIView" id="659685403">
Expand All @@ -47,8 +47,8 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUILabel" id="697203718">
<reference key="NSNextResponder" ref="659685403"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{10, 10}, {182, 21}}</string>
<int key="NSvFlags">294</int>
<string key="NSFrame">{{9, 10}, {200, 21}}</string>
<reference key="NSSuperview" ref="659685403"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand All @@ -69,8 +69,8 @@
</object>
<object class="IBUISwitch" id="297989004">
<reference key="NSNextResponder" ref="659685403"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{198, 8}, {94, 27}}</string>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{218, 8}, {94, 27}}</string>
<reference key="NSSuperview" ref="659685403"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand Down Expand Up @@ -98,6 +98,7 @@
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISelectionStyle">0</int>
Expand Down
Expand Up @@ -13,6 +13,7 @@
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765590DF743DE002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765580DF743DE002DB57D /* CoreGraphics.framework */; };
289233AE0DB2D0DB0083E9F9 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233A90DB2D0DB0083E9F9 /* MainViewController.m */; };
AA87D1DD113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = AA87D1DC113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.m */; };
AA8D0ED51136E17600EEB1C6 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = AA8D0ED31136E17600EEB1C6 /* MainWindow.xib */; };
DA33F59510BC2222004736E8 /* IASKAppSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DA33F57A10BC2222004736E8 /* IASKAppSettingsViewController.m */; };
DA33F59610BC2222004736E8 /* IASKSpecifierValuesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DA33F57C10BC2222004736E8 /* IASKSpecifierValuesViewController.m */; };
Expand Down Expand Up @@ -44,6 +45,8 @@
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* InAppSettingsKitSampleApp_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppSettingsKitSampleApp_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* InAppSettingsKitSampleApp-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "InAppSettingsKitSampleApp-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
AA87D1DB113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IASKPSTitleValueSpecifierViewCell.h; sourceTree = "<group>"; };
AA87D1DC113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IASKPSTitleValueSpecifierViewCell.m; sourceTree = "<group>"; };
AA8D0ED41136E17600EEB1C6 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainWindow.xib; sourceTree = "<group>"; };
AA8D0ED61136E18200EEB1C6 /* German */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = German; path = German.lproj/MainWindow.xib; sourceTree = "<group>"; };
DA33F57910BC2222004736E8 /* IASKAppSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IASKAppSettingsViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -198,6 +201,8 @@
DA33F58610BC2222004736E8 /* IASKPSTextFieldSpecifierViewCell.m */,
DA33F58710BC2222004736E8 /* IASKPSToggleSwitchSpecifierViewCell.h */,
DA33F58810BC2222004736E8 /* IASKPSToggleSwitchSpecifierViewCell.m */,
AA87D1DB113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.h */,
AA87D1DC113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.m */,
DA33F58910BC2222004736E8 /* IASKSlider.h */,
DA33F58A10BC2222004736E8 /* IASKSlider.m */,
DA33F58B10BC2222004736E8 /* IASKSwitch.h */,
Expand Down Expand Up @@ -316,6 +321,7 @@
DA33F59C10BC2222004736E8 /* IASKSlider.m in Sources */,
DA33F59D10BC2222004736E8 /* IASKSwitch.m in Sources */,
DA33F59E10BC2222004736E8 /* IASKTextField.m in Sources */,
AA87D1DD113FB0FA00101881 /* IASKPSTitleValueSpecifierViewCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
44 changes: 43 additions & 1 deletion InAppSettingsKitSampleApp/Settings.bundle/Complete.plist
Expand Up @@ -204,7 +204,7 @@
<key>Key</key>
<string>title_long</string>
<key>DefaultValue</key>
<string>Value with a very long text</string>
<string>Value with a very, very long text</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
Expand All @@ -230,6 +230,26 @@
<string>Three</string>
</array>
</dict>
<dict>
<key>Title</key>
<string>Title with a very, very loong label</string>
<key>Key</key>
<string>title_longtitle</string>
<key>DefaultValue</key>
<string>Value is long, too</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
<dict>
<key>Title</key>
<string></string>
<key>Key</key>
<string>title_withoutlabel</string>
<key>DefaultValue</key>
<string>Title without label</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
<dict>
<key>Title</key>
<string>Unexisting lookup entry</string>
Expand Down Expand Up @@ -398,6 +418,28 @@
<string>Three</string>
</array>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Multi Value with a long title</string>
<key>Key</key>
<string>multivalue_long</string>
<key>DefaultValue</key>
<integer>2</integer>
<key>Values</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
</array>
<key>Titles</key>
<array>
<string>One</string>
<string>Two</string>
<string>Three</string>
</array>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
Expand Down

0 comments on commit 03d6407

Please sign in to comment.