实现了一个类似腾讯新闻图文详情页的效果,不多说,上效果图
新闻.gif
Paste_Image.png
_textV = [UITextView new];
# 赋值
_textV.text = [NSString stringWithFormat:@"%d/%lu %@",1,(unsigned long)imageArray.count,[[MethodTool shareTool] cleanData:imageArray[0][@"title_name"]]];
_textV.backgroundColor = [UIColor clearColor];
# 使用户不可以编辑,只作展示用,不可设置交互性为NO,否则整个 TextV都不可滑动了。
_textV.editable = NO;
_textV.tag = 1000;
_textV.font = [UIFont systemFontOfSize:SMALL_FONT];
# 设置右侧的滑动条样式 indicatorStyle
# 滚动条的样式,基本只是设置颜色,总共3个颜色,默认是黑色的,此处修改为白色的。
_textV.indicatorStyle = UIScrollViewIndicatorStyleWhite;
# 设置 字体的行间距和字间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
# 字体的行间距
paragraphStyle.lineSpacing = Scale_Y(7);
# 字间距
paragraphStyle.paragraphSpacing = Scale_Y(3);
attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:SMALL_FONT],
NSParagraphStyleAttributeName:paragraphStyle,
NSForegroundColorAttributeName:[UIColor whiteColor]
};
# 字体风格的修改都是通过 attributedText 实现的
_textV.attributedText = [[NSAttributedString alloc] initWithString:_textV.text attributes:attributes];
_textV.textColor = [UIColor whiteColor];
# PS scrollIndicatorInsets 设置滚动条的位置
总结一下右侧的滚动条一直处于显示状态的原理:
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(run) userInfo:nil repeats:YES];
# 使右侧的滚动条一直不透明
-(void)run{
for(UIView *img in [_textV subviews]){
if ([img isKindOfClass:[UIImageView class]] && img.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin){
[img setAlpha:1];
}
}
}
整个效果中, UITextView的字体间距设置和 右侧滚动条一直保持显示状态是关键点。