概述
-(void)loadPagination{ pagination =[[UIView alloc] init];//页脚部分视图 UILabel *first =[[UILabel alloc] initWithFrame:CGRectMake(0,0,60,36)];//第几页显示 first.backgroundColor =[UIColor clearColor];//背景透明 first.text = [NSString stringWithFormat:@"第%d页",pageNow]; first.font =[UIFont systemFontOfSize:14]; [pagination addSubview:first];//添加到页脚视图 [first release];
int totalNumberOfPages = totalPages; UISlider *pageSlider =[[UISlider alloc] initWithFrame:CGRectMake(0+first.frame.size.width,0 (totalNumberOfPage -1)*20+18 ,36)]; //当前面的蓝点,翻页有变换位置 UIGraphicsBeginImageContext(CGSizeMake((totalNumberOfPages-1)*20+18 , 4)); UIImage *dot = [UIImage imageNamed:@"gray_dot.png"];//灰色小点的图片 for(int i =0; i < totalNumberOfPages; i++)//有几页就画几个点 { [dot drawInRect:CGRectMake(i*20+7), 0, 4, 4)]; } UIImage *trackImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [pageSlider setThumbImage:[UIImage imageNamed:"blue_dot.png"] forState:UIControlStateNormal];//小蓝点图片 [pageSlider setMinimumTrackImage:trackImage forState:UIControlStateNormal]; [pageSlider setMaximumTrackImage: trackImage forState:UIControlStateNormal]; pageSlider.maximumValue = totalNumerOfPages;//最大页码 pageSlider.minmumValue = 1;//最小页码 pageSlider.value = pageNow;//当前所在位置 pageSlider.userInteractionEnabled = NO; [pagination addSubview:pageSlider]; [pageSlider release];
UILabel *total = [[UILabel alloc] initWithFrame:CGRectMake(6+first.size.width+paageSlider.frame.size.width,0 , 64 ,36)];//共几页 total.backgroundColor =[UIColor clearColor]; total.text = [NSString stringWithFormat:@"共%i页" , totalNumberOfPages]; total.font = [UIFont systemFontOfSize:14]; [pagination addSubview:total ]; [total release ];
int width = first.frame.size.width + pageSlider.frame.size.width + total.frame.size.width; pagination.frame = CGRectMake((self.frame.size.width - width)/2 ,self.frame.size.height - 36, width, 36 ); [self addSubview: pagination];//将页脚添加到视图 [pagination realease]; |
最后
以上就是酷炫钢铁侠为你收集整理的IOS UISlider来显示页数、页码提示的全部内容,希望文章能够帮你解决IOS UISlider来显示页数、页码提示所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复