zl程序教程

您现在的位置是:首页 >  工具

当前栏目

[控件] 将字符串转换成贝塞尔曲线并执行动画

动画执行 字符串 控件 转换成 曲线 贝塞尔
2023-09-14 08:57:16 时间
@property (nonatomic, strong) NSString *text; @property (nonatomic, strong) UIFont *font; @property (nonatomic, strong) UIColor *lineColor; @property (nonatomic, assign) CGFloat lineWidth;
// Created by XianMingYou on 15/3/6. // Copyright (c) 2015年 XianMingYou. All rights reserved. #import "ShapeWordView.h" @interface ShapeWordView () @property (nonatomic, strong) CAShapeLayer *shapeLayer; @implementation ShapeWordView - (void)buildView { // 过滤数据 CGFloat lineWidth = (self.lineWidth = 0 ? 0.5 : self.lineWidth); UIFont *font = (self.font == nil ? [UIFont systemFontOfSize:18.f] : self.font); UIColor *lineColor = (self.lineColor == nil ? [UIColor blackColor] : self.lineColor); NSString *text = self.text; if (text == nil || text.length == 0) { return; // 初始化layer self.shapeLayer = [CAShapeLayer layer]; self.shapeLayer.frame = self.bounds; self.shapeLayer.lineWidth = lineWidth; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.shapeLayer.strokeColor = lineColor.CGColor; self.shapeLayer.path = [UIBezierPath pathForMultilineString:text withFont:font maxWidth:self.bounds.size.width textAlignment:NSTextAlignmentCenter].CGPath; self.shapeLayer.bounds = CGPathGetBoundingBox(self.shapeLayer.path); self.shapeLayer.geometryFlipped = YES; self.shapeLayer.strokeEnd = 0.f; [self.layer addSublayer:self.shapeLayer]; - (void)percent:(CGFloat)percent animated:(BOOL)animated { if (animated) { if (percent = 0) { self.shapeLayer.strokeEnd = 0; } else if (percent 0 percent = 1) { self.shapeLayer.strokeEnd = percent; } else { self.shapeLayer.strokeEnd = 1.f; } else { if (percent = 0) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 0; [CATransaction setDisableActions:NO]; } else if (percent 0 percent = 1) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = percent; [CATransaction setDisableActions:NO]; } else { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 1.f; [CATransaction setDisableActions:NO]; @end
使用:
//

// ViewController.m

// PathWord

// Created by XianMingYou on 15/3/6.

// Copyright (c) 2015年 XianMingYou. All rights reserved.

#import "ViewController.h"

#import "UIBezierPath+TextPaths.h"

#import "ShapeWordView.h"

@interface ViewController () UITableViewDelegate 

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) ShapeWordView *shape;

@implementation ViewController

- (void)viewDidLoad {

 [super viewDidLoad];


self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.tableView.delegate = self; [self.view addSubview:self.tableView]; self.shape = [[ShapeWordView alloc] initWithFrame:CGRectMake(10, 20, 290, 100)]; self.shape.lineColor = [UIColor redColor]; self.shape.text = @"YouXianMing"; self.shape.lineWidth = 0.5f; [self.shape buildView]; [self.view addSubview:self.shape]; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = - scrollView.contentOffset.y; if (offsetY = 0) { CGFloat percent = offsetY / 50; [self.shape percent:percent animated:NO]; @end

Winform控件优化之Paint事件实现圆角组件(提取绘制圆角的扩展方法) Paint事件方法中实现圆角控件不要通过事件参数`e.ClipRectangle`获取控件区域范围,原因见最后介绍;注意设置控件背景透明(参见[Winform控件优化之背景透明那些事2...
WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect 原文:WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.
利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同时增加鼠标的悬停效果。
WPF绘制光滑连续贝塞尔曲线 原文:WPF绘制光滑连续贝塞尔曲线 WPF本身没有直接把点集合绘制成曲线的函数。可以通过贝塞尔曲线函数来绘制。 贝塞尔曲线类是:BezierSegment,三次贝塞尔曲线,通过两个控制点来控制开始和结束方向。