相关疑难解决方法(0)

给UIView圆角

我的登录视图有一个子视图,其中有一个UIActivityView和一个UILabel说"登录...".此子视图的拐角不是圆角.我怎样才能让它们成圆形?

有没有办法在我的xib中做到这一点?

cocoa-touch uiview ios

562
推荐指数
11
解决办法
31万
查看次数

如何在UILabel周围画边框?

UILabel有没有办法在自己周围划出边界?这对我调试文本位置以及查看位置和标签实际大小非常有用.

iphone cocoa-touch uikit uilabel ios

135
推荐指数
4
解决办法
11万
查看次数

如何在CALayer上进行转换?

在写这个问题之前,我已经

但是,我仍然无法理解如何在图层上进行基本变换.寻找翻译,旋转和缩放的解释和简单示例一直很困难.

今天我终于决定坐下来,做一个测试项目,然后把它们搞清楚.我的答案如下.

笔记:

  • 我只做Swift,但如果有人想要添加Objective-C代码,请成为我的客人.
  • 在这一点上,我只关心理解2D变换.

transform calayer ios swift

31
推荐指数
1
解决办法
3万
查看次数

在矩形 UIView 底部添加三角形尖端

我需要在 UIView 的中间添加一个提示。我想要实现的是一个自定义的谷歌地图标记,如下图所示。

到目前为止,我的代码只是绘制了一个没有三角形尖端的矩形 uiview。

编辑

我希望我的 UIView 在底部有一个三角形的尖端

UIView *infoView  =  [[UIView alloc] initWithFrame:CGRectMake(10, 85, screenWidth *0.25, 75)];
infoView.backgroundColor = [UIColor blueColor];
CGRect currentFrame = infoView.frame;


float strokeWidth = 3.0;
float HEIGHTOFPOPUPTRIANGLE = 75;
float WIDTHOFPOPUPTRIANGLE = screenWidth*0.25;
float borderRadius = 4;

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, strokeWidth);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);

// Draw and fill the bubble
CGContextBeginPath(context);
CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f - …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

7
推荐指数
1
解决办法
4343
查看次数

使用Playgrounds的Swift中的BezierPath

我是否必须创建自定义类才能在Swift游乐场中使用BezierPath?

以下代码仅显示黑色背景:

import UIKit
import XCPlayground

class GraphView : UIView {

    override func drawRect(rect: CGRect) {

        let path = UIBezierPath(rect: rect)
        path.moveToPoint(CGPointMake(0,0))
        path.addLineToPoint(CGPointMake(50,100))
        path.closePath()
        UIColor.redColor().setFill()

        path.stroke()
    }

}


let graphView = GraphView(frame: CGRectMake(0,0,960,640))
Run Code Online (Sandbox Code Playgroud)

ios swift

6
推荐指数
1
解决办法
1771
查看次数

如何绘制UIBezierPaths

这就是我想要做的事情:

我有一个UIBezierPath,我想将它传递给一些方法来绘制它.或者只是从创建它的方法中绘制它.

我不确定如何指出应该绘制哪个视图.所有绘图方法都必须从头开始

- (void)drawRect:(CGRect)rect { ...} ?
Run Code Online (Sandbox Code Playgroud)

我可不可以做

- (void)drawRect:(CGRect)rect withBezierPath:(UIBezierPath*) bezierPath { ... } ??
Run Code Online (Sandbox Code Playgroud)

如何从其他方法调用此函数或方法?

objective-c ios uibezierpath

5
推荐指数
2
解决办法
3万
查看次数

如何缩放UIBezierPath以适合当前视图(在Swift中)

我创建了一个使用从PaintCode导入的代码绘制咖啡杯的类,并将此类应用于视图.使用@IBDesignable,我可以在我的故事板中看到杯子正在视图中绘制,但整体形状太大了.我可以在代码中重新绘制形状,使其适合视图的当前大小,但是在绘制后无法缩放形状,以便在我的视图在不同设备上更改大小时,形状是否正确缩放?

我已经调查过,CGContextScaleCTM(aRef, <#sx: CGFloat#>, <#sy: CGFloat#>)但我不确定如何将CGRect我的视图转换bounds为正确的比例因子

我不想发布所有内容,但我的绘图代码就是这样开始的

bezierPath.moveToPoint(CGPointMake(64.8, 52.81))
bezierPath.addCurveToPoint(CGPointMake(58.89, 43.44), controlPoint1: CGPointMake(64.21, 48.28), controlPoint2: CGPointMake(62.11, 44.95))
bezierPath.addCurveToPoint(CGPointMake(56.82, 42.76), controlPoint1: CGPointMake(58.24, 43.13), controlPoint2: CGPointMake(57.55, 42.9))
Run Code Online (Sandbox Code Playgroud)

这样下去了

bezierPath.closePath()
bezierPath.miterLimit = 4
bezierPath.usesEvenOddFillRule = true;
Run Code Online (Sandbox Code Playgroud)

然后还有另外两个绘图代码块,用于绘制咖啡蒸汽的两条小线.我将这两条路径附加到原始路径bezierPath,然后设置填充颜色并填充整个形状.

scale uibezierpath swift ios8

5
推荐指数
2
解决办法
3607
查看次数

我可以在drawRect方法之外绘制圆形,矩形,直线等形状

我可以drawRect使用外部方法绘制圆形,矩形,线条等形状

CGContextRef contextRef = UIGraphicsGetCurrentContext();
Run Code Online (Sandbox Code Playgroud)

或者drawRect仅在内部使用它是强制性的.请帮帮我,让我知道如何在drawRect方法外绘制形状.实际上我想继续在touchesMoved事件上绘制点.

这是我绘制点的代码.

CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(contextRef, 0, 255, 0, 1);
CGContextFillEllipseInRect(contextRef, CGRectMake(theMovedPoint.x, theMovedPoint.y, 8, 8));
Run Code Online (Sandbox Code Playgroud)

drawrect ipad ios cgcontextref

4
推荐指数
1
解决办法
7789
查看次数