Skip to content

Commit

Permalink
prevent re-adding scrollview if already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
caydenliew committed Mar 15, 2012
1 parent 0c70ee6 commit a1e5fd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
Binary file not shown.
50 changes: 26 additions & 24 deletions CLTickerViewDemo/CLTickerView/CLTickerView.m
Expand Up @@ -42,32 +42,34 @@ - (CGSize)labelSizeForText:(NSString *)text forFont:(UIFont *)font {
- (void)drawRect:(CGRect)rect - (void)drawRect:(CGRect)rect
{ {
// Drawing code // Drawing code
CGSize labelSize = [self labelSizeForText:self.marqueeStr forFont:self.marqueeFont]; if (self.scrollview == nil) {
labelWidth = labelSize.width; CGSize labelSize = [self labelSizeForText:self.marqueeStr forFont:self.marqueeFont];

labelWidth = labelSize.width;
self.scrollview = [[CLScrollview alloc] initWithFrame:CGRectMake(0, 0,
self.scrollview = [[CLScrollview alloc] initWithFrame:CGRectMake(0, 0,
self.frame.size.width, self.frame.size.width,
self.frame.size.height)]; self.frame.size.height)];
self.scrollview.delegate = self; self.scrollview.delegate = self;
self.scrollview.customDelegate = self; self.scrollview.customDelegate = self;


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width, UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width,
0, 0,
labelSize.width, labelSize.width,
self.frame.size.height)]; self.frame.size.height)];
label.font = self.marqueeFont; label.font = self.marqueeFont;
label.backgroundColor = [UIColor clearColor]; label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor]; label.textColor = [UIColor whiteColor];
label.text = self.marqueeStr; label.text = self.marqueeStr;


[self.scrollview addSubview:label]; [self.scrollview addSubview:label];
[self addSubview:self.scrollview]; [self addSubview:self.scrollview];
[label release]; [label release];


contentWidth = 2 * self.frame.size.width + labelSize.width; contentWidth = 2 * self.frame.size.width + labelSize.width;
[self.scrollview setContentSize:CGSizeMake(contentWidth, self.frame.size.height)]; [self.scrollview setContentSize:CGSizeMake(contentWidth, self.frame.size.height)];
startScrolling = NO; startScrolling = NO;
[self startScrolling]; [self startScrolling];
}
} }


- (void)dealloc { - (void)dealloc {
Expand Down

0 comments on commit a1e5fd3

Please sign in to comment.