我有一个UIBezierPath
,我想得到它的镜像.我怎么能做到这一点?
// Method for generating a path
UIBezierPath *myPath = [self generateAPathInBounds:boundingRect];
// ? now I would like to mirror myPath ?
Run Code Online (Sandbox Code Playgroud) 我想在UIView中使用不同的笔触和填充颜色绘制多个UIBezierPath.
这是代码
- (void)drawRect:(CGRect)rect {
context = UIGraphicsGetCurrentContext();
[[UIColor grayColor] setFill];
[[UIColor greenColor] setStroke];
UIBezierPath *aPath = [[UIBezierPath alloc] init];
[aPath moveToPoint:CGPointMake(227,34.25)];
[aPath addLineToPoint:CGPointMake(298.25,34.75)];
[aPath addLineToPoint:CGPointMake(298.5,82.5)];
[aPath addLineToPoint:CGPointMake(251,83)];
[aPath addLineToPoint:CGPointMake(251,67.5)];
[aPath addLineToPoint:CGPointMake(227.25,66.75)];
[aPath closePath];
aPath.lineWidth = 2;
[aPath fill];
[aPath stroke];
UIBezierPath *aPath2 = [[UIBezierPath alloc] init];
[aPath2 moveToPoint:CGPointMake(251.25,90.5)];
[aPath2 addLineToPoint:CGPointMake(250.75,83.25)];
[aPath2 addLineToPoint:CGPointMake(298.5,83)];
[aPath2 addLineToPoint:CGPointMake(298.5,90.25)];
[aPath2 closePath];
aPath2.lineWidth = 2;
[aPath2 fill];
[aPath2 stroke];
[paths addObject:aPath2];
Run Code Online (Sandbox Code Playgroud)
问题是笔划和填充颜色是在当前上下文中设置的.是否可以在同一CGContextRef中绘制不同颜色的不同UIBezierPath?
或者我必须在单独的UIView中绘制每个UIBezierPath?
我正在尝试绘制自定义按钮框架,如下所示:
UIBezierPath *stroke = [UIBezierPath bezierPathWithRoundedRect:self.bounds
cornerRadius:RECT_CORNECR_RADIUS];
[stroke stroke];
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,角落曲线看起来比侧面更有思想性.如果你看看UIButton的默认框架,它是非常统一的.A是UIButton,B是自定义按钮.
任何想法我怎么能使它更像UIButton.
目前我正在开发iOS的绘图应用程序.我坚持将阴影效果应用于特定的绘制路径.我使用UIBezierpath绘制路径.有没有办法在UIBezierpath上应用阴影效果?
我是一个iOS新手.如何使我遵循字母表的UIBezierPath说"B".目标是跟踪沿此路径的接触.
提前致谢.
我正在开发一个与HairTryOn相同的应用程序.但问题在下图中显示.我想根据客户脸部设置发型,使用蓝线按照图像显示.我使用以下代码
testVw = [[UIView alloc]initWithFrame:CGRectMake(100,100, 100, 100)];
testVw.backgroundColor = [UIColor clearColor];
[self.view addSubview:testVw];
resizeVw = [[UIImageView alloc]initWithFrame:CGRectMake(testVw.frame.size.width-25, testVw.frame.size.height-25, 25, 25)];
resizeVw.backgroundColor = [UIColor clearColor];
resizeVw.userInteractionEnabled = YES;
resizeVw.image = [UIImage imageNamed:@"button_02.png" ];
[testVw addSubview:resizeVw];
UIPanGestureRecognizer* panResizeGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(resizeTranslate:)];
[testVw addGestureRecognizer:panResizeGesture];
Run Code Online (Sandbox Code Playgroud)
该resizeTranslate:
方法:
-(void)resizeTranslate:(UIPanGestureRecognizer *)recognizer
{
if ([recognizer state]== UIGestureRecognizerStateBegan)
{
prevPoint = [recognizer locationInView:testVw.superview];
[testVw setNeedsDisplay];
}
else if ([recognizer state] == UIGestureRecognizerStateChanged)
{
if (testVw.bounds.size.width < 20)
{
testVw.bounds = CGRectMake(testVw.bounds.origin.x, testVw.bounds.origin.y, 20,testVw.bounds.size.height);
imgvw.frame = …
Run Code Online (Sandbox Code Playgroud) 我有一个UIViewController
我想在屏幕上画一个椭圆CGPoint(x:160,y:160)
,宽度:240
,高度:320
.我怎么能在swift中做到这一点?我非常感谢任何帮助.
我有一个关于UIBezierPath的问题.
例如,我有这条路:
现在我想要一个从白色到红色的颜色渐变.从左到右.
这是我的代码:
UIBezierPath *bezierPath;
bezierPath = [UIBezierPath bezierPathWithArcCenter:_center radius:_radius startAngle:((4 * angle)) endAngle:(((20) * angle)) clockwise:YES];
[bezierPath addLineToPoint:_center];
[bezierPath closePath];
UIColor *color = [UIColor colorWithHue:0/sectors saturation:1. brightness:1. alpha:1];
[color setFill];
[color setStroke];
[bezierPath fill];
[bezierPath stroke];
Run Code Online (Sandbox Code Playgroud)
谁能帮我?
编辑1:
我有这个色轮:
UIBezierPath *bezierPath;
for ( int i = 0; i < 360; i++) {
bezierPath = [UIBezierPath bezierPathWithArcCenter:_center radius:_radius startAngle:((i * angle)) endAngle:(((i + 1) * angle)) clockwise:YES];
[bezierPath addLineToPoint:_center];
[bezierPath closePath];
UIColor *color = [UIColor colorWithHue:i/sectors saturation:1. brightness:1. alpha:1]; …
Run Code Online (Sandbox Code Playgroud) 我知道有一种绘制圆形的方法 - UIBezierPath(roundedRect, cornerRadius)
但是我想知道如果我自己剪辑角落,为什么我必须在绘制矩形之前添加剪辑?(我觉得在绘制之后剪切矩形更合理.我错过了什么概念?)
(1)工作
override func drawRect(rect: CGRect) {
var clipPath = UIBezierPath(roundedRect: rect, cornerRadius: 8.0)
path.addClip()
var rectPath = UIBezierPath(rect: rect)
UIColor.redColor().setFill()
rectPath.fill()
}
Run Code Online (Sandbox Code Playgroud)
(2)不工作
override func drawRect(rect: CGRect) {
var rectPath = UIBezierPath(rect: rect)
UIColor.redColor().setFill()
rectPath.fill()
var clipPath = UIBezierPath(roundedRect: rect, cornerRadius: 8.0)
path.addClip()
}
Run Code Online (Sandbox Code Playgroud) 我做了一个圆圈路径,圆圈路径的中心位于视图的中间.然后,我做了一个只能在圆圈路径上移动的球(至少这是我想要的):
我做了一个函数,无论我在哪里拖动它都会移动球(仅限于圆形路径),但出于某种原因,每当我拖动它时,它就会变得疯狂并且不会移动,因为我希望它移动.
到目前为止这是我的代码:
class ViewController: UIViewController {
var midViewX = CGFloat()
var midViewY = CGFloat()
var circlePath2 = UIBezierPath()
var shapeLayer2 = CAShapeLayer()
override func viewDidLoad() {
super.viewDidLoad()
midViewX = view.frame.midX
midViewY = view.frame.midY
// Do any additional setup after loading the view, typically from a nib.
let circlePath = UIBezierPath(arcCenter: CGPoint(x: midViewX,y: midViewY), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.strokeColor = UIColor.redColor().CGColor
shapeLayer.lineWidth = 3.0
view.layer.addSublayer(shapeLayer) …
Run Code Online (Sandbox Code Playgroud) uibezierpath ×10
ios ×9
swift ×3
objective-c ×2
bezier ×1
character ×1
ios8 ×1
iphone ×1
shadow ×1
uibutton ×1
uiimageview ×1
uikit ×1
uiview ×1
xcode6 ×1