Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add scrollview

I converted the component from UIView in UIScrollView, so as to manage the scrolling;
Fixed resizing after rotation;
  • Loading branch information...
commit d14f191779d73098730e8bc28b5613db9fc0c3c8 1 parent c82df61
@kajinka13 kajinka13 authored
View
4 DWTagList.xcodeproj/project.pbxproj
@@ -18,6 +18,7 @@
04DEC62015A897B80034CA79 /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 04DEC61E15A897B80034CA79 /* ViewController_iPad.xib */; };
04DEC62915A8988A0034CA79 /* DWTagList.m in Sources */ = {isa = PBXBuildFile; fileRef = 04DEC62815A8988A0034CA79 /* DWTagList.m */; };
04DEC62B15A898EF0034CA79 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04DEC62A15A898EF0034CA79 /* QuartzCore.framework */; };
+ 2D195BD416FBAC890069A5E3 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2D195BD316FBAC890069A5E3 /* Default-568h@2x.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -38,6 +39,7 @@
04DEC62715A8988A0034CA79 /* DWTagList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DWTagList.h; sourceTree = "<group>"; };
04DEC62815A8988A0034CA79 /* DWTagList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DWTagList.m; sourceTree = "<group>"; };
04DEC62A15A898EF0034CA79 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ 2D195BD316FBAC890069A5E3 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -58,6 +60,7 @@
04DEC5F715A897B70034CA79 = {
isa = PBXGroup;
children = (
+ 2D195BD316FBAC890069A5E3 /* Default-568h@2x.png */,
04DEC60C15A897B80034CA79 /* DWTagList */,
04DEC60515A897B70034CA79 /* Frameworks */,
04DEC60315A897B70034CA79 /* Products */,
@@ -172,6 +175,7 @@
04DEC61115A897B80034CA79 /* InfoPlist.strings in Resources */,
04DEC61D15A897B80034CA79 /* ViewController_iPhone.xib in Resources */,
04DEC62015A897B80034CA79 /* ViewController_iPad.xib in Resources */,
+ 2D195BD416FBAC890069A5E3 /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
4 DWTagList/Classes/DWTagList.h
@@ -15,7 +15,7 @@
@end
-@interface DWTagList : UIView
+@interface DWTagList : UIScrollView
{
UIView *view;
NSArray *textArray;
@@ -26,7 +26,7 @@
@property (nonatomic) BOOL viewOnly;
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) NSArray *textArray;
-@property (nonatomic, strong) id<DWTagListDelegate> delegate;
+@property (nonatomic, weak) id<DWTagListDelegate> tagDelegate;
@property (nonatomic, strong) UIColor *highlightedBackgroundColor;
- (void)setLabelBackgroundColor:(UIColor *)color;
View
36 DWTagList/Classes/DWTagList.m
@@ -31,13 +31,24 @@ - (void)touchedTag:(id)sender;
@implementation DWTagList
@synthesize view, textArray;
-@synthesize delegate = _delegate;
+@synthesize tagDelegate = _tagDelegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self addSubview:view];
+ [self setClipsToBounds:YES];
+ self.highlightedBackgroundColor = HIGHLIGHTED_BACKGROUND_COLOR;
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder *)aDecoder {
+ self = [super initWithCoder:aDecoder];
+ if (self) {
+ [self addSubview:view];
+ [self setClipsToBounds:YES];
self.highlightedBackgroundColor = HIGHLIGHTED_BACKGROUND_COLOR;
}
return self;
@@ -74,8 +85,15 @@ - (void)touchedTag:(id)sender
{
UITapGestureRecognizer *t = (UITapGestureRecognizer *)sender;
UILabel *label = (UILabel *)t.view;
- if(label && self.delegate && [self.delegate respondsToSelector:@selector(selectedTag:)])
- [self.delegate selectedTag:label.text];
+ if(label && self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(selectedTag:)])
+ [self.tagDelegate selectedTag:label.text];
+}
+
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+
+ [self display];
}
- (void)display
@@ -144,6 +162,7 @@ - (void)display
}
}
sizeFit = CGSizeMake(self.frame.size.width, totalHeight + 1.0f);
+ self.contentSize = sizeFit;
}
- (CGSize)fittedSize
@@ -161,8 +180,8 @@ - (void)touchUpInside:(id)sender
{
UIButton *button = (UIButton*)sender;
[button setBackgroundColor:[UIColor clearColor]];
- if(button && self.delegate && [self.delegate respondsToSelector:@selector(selectedTag:)])
- [self.delegate selectedTag:button.accessibilityLabel];
+ if(button && self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(selectedTag:)])
+ [self.tagDelegate selectedTag:button.accessibilityLabel];
}
- (void)touchDragExit:(id)sender
@@ -177,4 +196,11 @@ - (void)touchDragInside:(id)sender
[button setBackgroundColor:self.highlightedBackgroundColor];
}
+- (void)dealloc
+{
+ view = nil;
+ textArray = nil;
+ lblBackgroundColor = nil;
+}
+
@end
View
4 DWTagList/ViewController.m
@@ -23,10 +23,10 @@ - (void)selectedTag:(NSString *)tagName{
- (void)viewDidLoad
{
[super viewDidLoad];
- tagList = [[DWTagList alloc] initWithFrame:CGRectMake(20.0f, 70.0f, 280.0f, 300.0f)];
+ tagList = [[DWTagList alloc] initWithFrame:CGRectMake(20.0f, 70.0f, 180.0f, 50.0f)];
NSArray *array = [[NSArray alloc] initWithObjects:@"Foo", @"Tag Label 1", @"Tag Label 2", @"Tag Label 3", @"Tag Label 4", @"Tag Label 5", nil];
[tagList setTags:array];
- [tagList setDelegate:self];
+ [tagList setTagDelegate:self];
[self.view addSubview:tagList];
}
View
BIN  Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.