I have a custom cell for my UITableView. If the user chose a picture for an item cell will show a picture:
if not, I will show first two characters of the item name:
I'm using following code from paint code to make rectangle:
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
I showed part of code because it's too long.
Then I used a UIView to draw this rectangle:
import UIKit
class CirclyStyleView: UIView {
override func draw(_ rect: CGRect) {
CircleStyleKit.drawCanvas1()
}
}
}
There are two problems:
First, if I use UIImageView in my storyboard I just can draw an image and I don't know if I can draw a rectangle with my code or not. However, I checked it doesn't work.
Second if I use UIView, I can draw a rectangle, but if I want to draw an image I should use
UIColor(patternImage: UIImage(named: "picName")!)
, but I can't change this image frame the way I did for image view. For example, make it circle as I've shown in the picture.The question is, can I use UIImageView and is there any way to make my rectangle in UIImageView Or can I use UIView and is there any way to set my custom image. I mean change image size and frame.