Created
September 4, 2013 13:44
-
-
Save rcdilorenzo/6437136 to your computer and use it in GitHub Desktop.
Answer in reference to Stack Overflow question: http://stackoverflow.com/questions/18614536/how-to-create-uiscrollview-with-custom-shapes-in-ios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IMAGE_WIDTH 100.0 | |
#define IMAGE_HEIGHT 100.0 | |
@implementation SOMaskScrollView | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
self.backgroundColor = [UIColor whiteColor]; | |
// Initialization code | |
} | |
return self; | |
} | |
- (void)layoutSubviews { | |
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.frame]; | |
CGFloat totalImages = 20; | |
UIImage *repeatImage = [UIImage imageNamed:@"stripe_black.png"]; | |
scrollView.contentSize = CGSizeMake(self.frame.size.width, totalImages*IMAGE_HEIGHT); | |
for (int count = 0; count < totalImages; count++) { | |
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, count*IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT)]; | |
imageView.image = repeatImage; | |
[scrollView addSubview:imageView]; | |
} | |
[self addSubview:scrollView]; | |
CAShapeLayer *maskLayer = [CAShapeLayer layer]; | |
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(self.frame, 5, 5) cornerRadius:50.0f].CGPath; | |
self.layer.mask = maskLayer; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment