Tag: drawrect

如何绘制UIImage或直接在-drawRect中:?

我有一个UIImage ,我想在UIView上绘制。 但是,而不是创build一个UIImageView并将其添加为子视图,我想覆盖-drawRect:并直接绘制我的UIView。 例如,我的代码如下所示: – (void)drawRect:(CGRect)rect { CGContextRef myContext = UIGraphicsGetCurrentContext(); UIImage *img = [UIImage imageNamed:@"foo.png"]; // how to draw the directly into the view now? }

animation绘制一个圆圈

我正在寻找一种方法来创build一个圆圈的绘图animation。 我已经能够创造出这个圈子,但它一起吸引了所有人。 这是我的CircleView类: import UIKit class CircleView: UIView { override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = UIColor.clearColor() } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func drawRect(rect: CGRect) { // Get the Graphics Context var context = UIGraphicsGetCurrentContext(); // Set the circle outerline-width CGContextSetLineWidth(context, 5.0); // Set the circle […]