标签:
@interface YSWeiBoExpressionView ()<UIScrollViewDelegate>
/** 表情scrollecView */
@property (nonatomic, weak) UIScrollView *expressionScrollView;
/** pageControll */
@property (nonatomic, weak) UIPageControl *expressionPageControl;
@end
#pragma mark - Controll
- (UIScrollView *)expressionScrollView
{
if (!_expressionScrollView)
{
UIScrollView *expressionScrollView = [[UIScrollView alloc] init];
expressionScrollView.backgroundColor = [UIColor grayColor];
expressionScrollView.opaque = YES;
expressionScrollView.pagingEnabled = YES;
expressionScrollView.showsHorizontalScrollIndicator = NO;
expressionScrollView.showsVerticalScrollIndicator = NO;
expressionScrollView.delegate = self;
self.expressionScrollView = expressionScrollView;
[self addSubview:expressionScrollView];
}
return _expressionScrollView;
}
- (UIPageControl *)expressionPageControl
{
if (!_expressionPageControl)
{
UIPageControl *expressionPageControl = [[UIPageControl alloc] init];
expressionPageControl.backgroundColor = [UIColor yellowColor];
expressionPageControl.pageIndicatorTintColor = [UIColor whiteColor];
expressionPageControl.currentPageIndicatorTintColor = [UIColor orangeColor];
expressionPageControl.userInteractionEnabled = NO;
expressionPageControl.hidesForSinglePage = YES; // 单页隐藏
self.expressionPageControl = expressionPageControl;
[self addSubview:expressionPageControl];
}
return _expressionPageControl;
}
#pragma mark - Layouts
- (void)layoutSubviews
{
[super layoutSubviews];
self.expressionPageControl.width = self.width;
self.expressionPageControl.height = 35;
self.expressionPageControl.x = 0;
self.expressionPageControl.y = self.height - self.expressionPageControl.height;
self.expressionScrollView.width = self.width;
self.expressionScrollView.height = self.expressionPageControl.y;
self.x = 0;
self.y = 0;
NSInteger pageCount = self.expressionScrollView.subviews.count;
for (int i = 0; i < pageCount; i++)
{
YSWeiBoExpressionEmojiView *emotionsPageView = self.expressionScrollView.subviews[i];
emotionsPageView.width = self.expressionScrollView.width;
emotionsPageView.height = self.expressionScrollView.height;
emotionsPageView.x = emotionsPageView.width * i;
emotionsPageView.y = 0;
}
self.expressionScrollView.contentSize = CGSizeMake(pageCount * self.expressionScrollView.width, 0);
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
double pageNumber = scrollView.contentOffset.x / scrollView.frame.size.width;
self.expressionPageControl.currentPage = (int)(pageNumber + 0.5);
}
UIScrollView和UIPageControl结合使用
标签:
原文地址:http://www.cnblogs.com/happyEveryData/p/5520890.html