ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

OCBarrage弹幕样式配置清单:字体、颜色、描边、圆角、速度属性全解

OCBarrage弹幕样式配置清单:字体、颜色、描边、圆角、速度属性全解 OCBarrage弹幕样式配置清单字体、颜色、描边、圆角、速度属性全解【免费下载链接】OCBarrageiOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!项目地址: https://gitcode.com/gh_mirrors/oc/OCBarrageOCBarrage 是一款面向 iOS 的高性能弹幕库barrage render-engine底层基于 Core Animation 驱动、Core Graphics 绘图、GPU 渲染同时渲染 5000 条弹幕也不卡顿。对新手来说配置一条弹幕的外观与速度只需一个「描述符对象」本文把字体、颜色、描边、圆角、边框、速度等全部样式属性整理成一份可直接照抄的配置清单。两条弹幕的样式都从描述符开始配置OCBarrage 的所有样式配置集中在数据模型层分为两层基类OCBarrageDescriptor负责所有弹幕通用的属性——圆角、边框、速度、渲染范围、层级优先级定义见 OCBarrageDescriptor.h文本子类OCBarrageTextDescriptor负责文字类弹幕的字体、文字颜色、描边、阴影定义见 OCBarrageTextDescriptor.h自定义弹幕样式时继承这两层继续扩展即可示例可见OCBarrage/OtherDescriptorAndCells/目录下的 Gif、图字混排、横幅等实现。弹幕字体与颜色配置textFont、textColor 怎么设属性默认值说明textFont系统 17pt弹幕字体与字号支持任意UIFonttextColor白色文字颜色text/attributedText无弹幕内容富文本可局部修改样式默认值定义在 OCBarrageTextDescriptor.m不设置时自动回退到 17pt 系统字体 白色文字黑色文字场景记得显式指定。设置attributedText后可以逐字控制字体颜色适合做「重点词高亮」效果。弹幕描边 vs 阴影strokeColor 性能更优这是新手最容易踩坑的一组属性属性默认值说明textShadowOpenedNO阴影总开关开启后描边会失效shadowColor黑色阴影颜色shadowOffset零点阴影偏移shadowRadius2.0阴影模糊半径shadowOpacity0.5阴影不透明度strokeColor无描边笔画填充颜色strokeWidth0负值为填充效果正值中空效果两个关键点官方推荐使用strokeColor替代阴影关闭文字阴影可大幅提升性能描边比阴影「性能更强悍」见 OCBarrageTextDescriptor.h 中的注释。strokeWidth负正值语义不同取值为负是「填充」效果取值为正呈现「中空」空心字效果。弹幕圆角与边框配置cornerRadius、borderWidth、borderColor圆角、边框作用于整条弹幕的容器图层配置逻辑见 OCBarrageCell.m 中的addBorderAttributescornerRadius弹幕圆角大于 0 时生效注释标注默认 8borderWidth边框宽度默认 0无边框borderColor边框颜色默认无边框色想要「胶囊形弹幕」典型组合是圆角取弹幕高度的一半、边框 1pt、边框色与主题色一致。弹幕速度配置animationDuration 与 fixedSpeed 二选一速度相关属性在 OCBarrageDescriptor.h 中定义两者只能选一个属性取值行为animationDuration秒动画时长时间越长速度越慢越短越快fixedSpeed0.0 ~ 100.0固定速度防止空闲轨道下弹幕重叠设置后无需再设animationDuration实现上见 OCBarrageTextCell.m 的addBarrageAnimationWithDelegate:只要fixedSpeed 0就会优先启用固定速度动画时长由屏幕宽度自动换算因此不同尺寸设备上速度表现一致超过 100 的取值会被自动截断为 100。想让所有弹幕「匀速不重叠」用fixedSpeed推荐取值越大越快想让不同弹幕「快慢各异」用animationDuration弹幕渲染范围与遮挡优先级附赠两个属性renderRange弹幕渲染的纵向范围最终 Y 坐标不小于location、不超过length - 弹幕高度可用于把弹幕限制在屏幕下半区。positionPriority四级优先级 Low / Middle / High / Very High见 OCBarrageHeader.h数值高的弹幕渲染在上层适合把 VIP 弹幕置顶展示。弹幕样式配置速查表一张表抄走类别属性默认值建议字体textFont17pt 系统字体按需调整字号颜色textColor白色深色背景用白色描边strokeColorstrokeWidth无优先于阴影性能更好阴影textShadowOpened等 5 个关闭高负载场景保持关闭圆角cornerRadius大于 0 生效高度/2 即胶囊边框borderWidthborderColor0 / 无1pt 细边框更精致速度animationDuration/fixedSpeed—二选一推荐 fixedSpeed布局renderRange/positionPriority—限制范围与层级最小示例一条带描边胶囊弹幕OCBarrageTextDescriptor *descriptor [OCBarrageTextDescriptor new]; descriptor.text OCBarrage5000 条弹幕也不卡; descriptor.textFont [UIFont boldSystemFontOfSize:17.0]; descriptor.textColor [UIColor whiteColor]; descriptor.strokeColor [UIColor blackColor]; descriptor.strokeWidth -3; // 负值填充式描边 descriptor.cornerRadius 18.0; descriptor.borderWidth 1.0; descriptor.borderColor [UIColor orangeColor]; descriptor.fixedSpeed 30.0; // 固定速度0.0~100.0 [manager renderBarrageDescriptor:descriptor];常见弹幕样式效果预览普通文字弹幕上方演示动图行走横幅、图字混排等高级样式OCBarrage/Demonstration/walkBarrage.gif、OCBarrage/Demonstration/mixedImageAndText.gif更多弹幕类型Gif、渐变背景、竖排文字源码见 OCBarrage/OtherDescriptorAndCells/ 目录小结字体颜色改OCBarrageTextDescriptor圆角边框速度改OCBarrageDescriptor性能敏感时优先描边不用阴影速度优先选fixedSpeed——按这份清单配置你就能快速搭出风格统一的弹幕效果。【免费下载链接】OCBarrageiOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!项目地址: https://gitcode.com/gh_mirrors/oc/OCBarrage创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表