我有我的UITableView自定义单元格。如果用户选择一个项目单元的图片会显示一张图片: 使用UIImageView或UIView进行快速绘制
我用下面的绘制代码代码使长方形:
public class CircleStyleKit : NSObject {
//// Drawing Methods
public dynamic class func drawCanvas1(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 38, height: 38), resizing: ResizingBehavior = .aspectFit, circleLable: String = "DR", circleSize: CGSize = CGSize(width: 38, height: 38), textSize: CGFloat = 17) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()!
//// Resize to Target Frame
context.saveGState()
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 38, height: 38), target: targetFrame)
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
context.scaleBy(x: resizedFrame.width/38, y: resizedFrame.height/38)
} // It's too long
我显示了部分代码,因为它太长了。
然后我用一个UIView绘制这个矩形:
import UIKit
class CirclyStyleView: UIView {
override func draw(_ rect: CGRect) {
CircleStyleKit.drawCanvas1()
}
}
}
有两个问题:
首先,如果我在故事板使用的UIImageView我只可以得出一个图像 和我不知道是否可以用我的代码绘制矩形。但是,我 检查它不起作用。
其次,如果我使用UIView,我可以绘制一个矩形,但是如果我想绘制图像,我应该使用
UIColor(patternImage: UIImage(named: "picName")!)
,但我无法像改变图像视图一样改变这个图像帧。例如,让它像我在图片中显示的那样循环。问题是,我可以使用UIImageView,并有任何方式来使我的矩形在UIImageView 或者我可以使用UIView,并有任何方式来设置我的自定义图像。我的意思是改变图像大小和框架。