Skip to content

Commit

Permalink
Better UI7AlertView implementation
Browse files Browse the repository at this point in the history
color, stroke, button positions
  • Loading branch information
youknowone committed Jun 15, 2013
1 parent c344172 commit 937d022
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 61 deletions.
2 changes: 1 addition & 1 deletion UI7Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
38740493176825D900C0BB18 /* UI7Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UI7Utilities.m; sourceTree = "<group>"; };
3888FC60176C7C7900489638 /* UITIssue1ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITIssue1ViewController.h; sourceTree = "<group>"; };
3888FC61176C7C7900489638 /* UITIssue1ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UITIssue1ViewController.m; sourceTree = "<group>"; };
3888FC64176C8EBB00489638 /* libPods.a */ = {isa = PBXFileReference; lastKnownFileType = file; name = libPods.a; path = "Pods/build/Release-iphoneos/libPods.a"; sourceTree = "<group>"; };
3888FC64176C8EBB00489638 /* libPods.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPods.a; path = "Pods/build/Release-iphoneos/libPods.a"; sourceTree = "<group>"; };
38BC0E5A173E821700F36497 /* UITSubviewTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITSubviewTableViewController.h; sourceTree = "<group>"; };
38BC0E5B173E821700F36497 /* UITSubviewTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UITSubviewTableViewController.m; sourceTree = "<group>"; };
38C7A9761495181800381910 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down
24 changes: 13 additions & 11 deletions UI7Kit/UI7AlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ - (UIView *)frameView {
}

- (void)setFrameView:(UIView *)frameView {
[UI7AlertViewFrameViews setObject:frameView forKey:self.pointerString];
UI7AlertViewFrameViews[self.pointerString] = frameView;
}

- (UIView *)strokeView {
return [UI7AlertViewStrokeViews :self.pointerString];
}

- (void)setStrokeView:(UIView *)strokeView {
[UI7AlertViewStrokeViews setObject:strokeView forKey:self.pointerString];
UI7AlertViewStrokeViews[self.pointerString] = strokeView;
}

@end
Expand Down Expand Up @@ -131,7 +131,7 @@ - (id)init {
if (self != nil) {
self.backgroundImageView = [UIImage blankImage].view;
UIView *frameView = self.frameView = [[[UIView alloc] initWithFrame:CGRectMake(.0, .0, 284.0, 141.0)] autorelease];
frameView.backgroundColor = [UIColor iOS7BackgroundColor]; // temp
frameView.backgroundColor = [UIColor colorWith8BitWhite:233 alpha:255];

self.strokeView = [[UIView alloc] initWithFrame:CGRectMake(.0, .0, frameView.frame.size.width, 0.5)];
self.strokeView.backgroundColor = [UIColor colorWith8BitWhite:182 alpha:255];
Expand All @@ -151,14 +151,9 @@ - (void)show {
self.titleLabel.font = [UIFont iOS7SystemFontOfSize:16.0 weight:UI7FontWeightMedium];
self.bodyTextLabel.font = [UIFont iOS7SystemFontOfSize:16.0 weight:UI7FontWeightLight];

{
CGRect frame = self.strokeView.frame;
frame.origin.y = self.bodyTextLabel.frame.origin.y + self.bodyTextLabel.frame.size.height + 29.5f;
self.strokeView.frame = frame;
}

self.frameView.frame = self.bounds;

CGFloat highest = self.frame.size.height;
for (UIAlertButton *button in self.buttons) {
button.titleLabel.font = [UIFont iOS7SystemFontOfSize:16.0 weight:UI7FontWeightLight];
[button setTitleColor:[UIColor iOS7ButtonTitleColor] forState:UIControlStateNormal];
Expand All @@ -168,9 +163,16 @@ - (void)show {
[button setBackgroundImage:nil forState:UIControlStateHighlighted];

CGRect frame = button.frame;
frame.size.height = 45.0;
frame.origin.y = self.strokeView.frame.origin.y + 0.5f;
frame.origin.y += 16.0;
button.frame = frame;

highest = MIN(highest, button.frame.origin.y);
}

{
CGRect frame = self.strokeView.frame;
frame.origin.y = highest - 0.5f;
self.strokeView.frame = frame;
}
}

Expand Down
8 changes: 4 additions & 4 deletions UI7Kit/UI7ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ - (void)setTitle:(NSString *)title {
}

- (UINavigationItem *)navigationItem {
UI7NavigationItem *item = [UI7ViewControllerNavigationItems objectForKey:self.pointerString];
UI7NavigationItem *item = UI7ViewControllerNavigationItems[self.pointerString];
if (item == nil) {
item = [[[UI7NavigationItem alloc] initWithTitle:self.title] autorelease];
[UI7ViewControllerNavigationItems setObject:item forKey:self.pointerString];
UI7ViewControllerNavigationItems[self.pointerString] = item;
}
return item;
}

- (UIBarButtonItem *)editButtonItem {
UI7BarButtonItem *item = [UI7ViewControllerEditButtonItems objectForKey:self.pointerString];
UI7BarButtonItem *item = UI7ViewControllerEditButtonItems[self.pointerString];
if (item == nil) {
item = [[[UI7BarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(_toggleEditing:)] autorelease];
[UI7ViewControllerEditButtonItems setObject:item forKey:self.pointerString];
UI7ViewControllerEditButtonItems[self.pointerString] = item;
}
return item;
}
Expand Down
62 changes: 55 additions & 7 deletions UI7KitTestApp/Storyboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,78 @@
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Vaf-yU-zYZ">
<rect key="frame" x="26" y="20" width="42" height="21"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="AlertView" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Vaf-yU-zYZ">
<rect key="frame" x="26" y="20" width="72" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="ActionSheet" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="kD0-hC-u3c">
<rect key="frame" x="26" y="68" width="92" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="DO1-E7-Zsc">
<rect key="frame" x="136" y="21" width="79" height="27"/>
<rect key="frame" x="170" y="68" width="79" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="showActionSheet:" destination="Sei-zQ-6Ij" eventType="valueChanged" id="t1p-gB-Rzu"/>
</connections>
</switch>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="ezP-2L-6yL">
<rect key="frame" x="227" y="9" width="73" height="44"/>
<rect key="frame" x="101" y="9" width="65" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Button">
<state key="normal" title="Basic">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showAlertView1:" destination="Sei-zQ-6Ij" eventType="touchUpInside" id="5rx-H0-kor"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="b0d-EH-ukc">
<rect key="frame" x="178" y="9" width="61" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Long">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showAlertView2:" destination="Sei-zQ-6Ij" eventType="touchUpInside" id="cGb-DN-wEN"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="hL4-Zq-ZFL">
<rect key="frame" x="252" y="9" width="63" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Many">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showAlertView3:" destination="Sei-zQ-6Ij" eventType="touchUpInside" id="oH3-bt-2Pi"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="Detail" id="VmR-2N-0ni"/>
<navigationItem key="navigationItem" title="Detail" id="VmR-2N-0ni">
<barButtonItem key="rightBarButtonItem" title="IBButton" id="elb-uV-DKT"/>
</navigationItem>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="EoT-Ud-iQ4" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand All @@ -256,7 +301,10 @@
<class className="UITDetailViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/UITDetailViewController.h"/>
<relationships>
<relationship kind="outlet" name="detailDescriptionLabel" candidateClass="UILabel"/>
<relationship kind="action" name="showActionSheet:"/>
<relationship kind="action" name="showAlertView1:"/>
<relationship kind="action" name="showAlertView2:"/>
<relationship kind="action" name="showAlertView3:"/>
</relationships>
</class>
<class className="UITIssue1ViewController" superclassName="UITableViewController">
Expand Down
7 changes: 4 additions & 3 deletions UI7KitTestApp/UITDetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

@interface UITDetailViewController : UIViewController

@property (strong, nonatomic) id detailItem;

@property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
- (IBAction)showAlertView1:(id)sender;
- (IBAction)showAlertView2:(id)sender;
- (IBAction)showAlertView3:(id)sender;
- (IBAction)showActionSheet:(id)sender;

@end
56 changes: 22 additions & 34 deletions UI7KitTestApp/UITDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,40 @@
#import "UITDetailViewController.h"

@interface UITDetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;

@end

@implementation UITDetailViewController

- (void)dealloc
{
[_detailItem release];
[_detailDescriptionLabel release];
[super dealloc];
}

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
[_detailItem release];
_detailItem = [newDetailItem retain];
}
@implementation UITDetailViewController

if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Detail", @"Detail");
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)showAlertView1:(id)sender {
NSString *title = @"Title";
NSString *message = @"Message";
[UIAlertView showNoticeWithTitle:title message:message cancelButtonTitle:@"OK"];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)showAlertView2:(id)sender {
NSString *title = @"Is this test string can be as long as long cat? Or should I test long long longer cat? Like, caaaaaaaaaaaaaaaaaaaaaaaaaaat? I doubt even there is limitation of lines of title or not. Say, is this become long as much as burst to top and bottom of screen? And how much sentence should I write down to reach the end of the screen? I am not a good author. I feel tired to write this sentences.";
NSString *message = @"Is this test string can be as long as long cat? I don't know how much it long, but it should be long enough to finish my test.";
UIAlertView *view = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[view show];
[view release];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Detail", @"Detail");
}
return self;
- (void)showAlertView3:(id)sender {
NSString *title = @"Common title";
NSString *message = @"Uncommon buttons";
UIAlertView *view = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1", @"Button2", @"Button3", @"Button4", @"Button5", nil];
[view show];
[view release];
}

@end
2 changes: 1 addition & 1 deletion UI7KitTestApp/UITSubviewTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (NSUInteger)subviewTableViewNumberOfSubviews:(UIASubviewTableView *)scrollView
}

- (UIView *)subviewTableView:(UIASubviewTableView *)scrollView viewForRow:(NSUInteger)row {
return [self->views objectAtIndex:row];
return self->views[row];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down

0 comments on commit 937d022

Please sign in to comment.