mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			83 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			83 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Swift
		
	
//  Copyright (c) 2020 Open Whisper Systems. All rights reserved.
 | 
						|
 | 
						|
import UIKit
 | 
						|
import SignalCoreKit
 | 
						|
 | 
						|
@objc (OWSCircleView)
 | 
						|
public class CircleView: UIView {
 | 
						|
 | 
						|
    @available(*, unavailable, message:"use other constructor instead.")
 | 
						|
    required public init?(coder aDecoder: NSCoder) {
 | 
						|
        notImplemented()
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    public required init() {
 | 
						|
        super.init(frame: .zero)
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    public required init(diameter: CGFloat) {
 | 
						|
        super.init(frame: .zero)
 | 
						|
 | 
						|
        autoSetDimensions(to: CGSize(width: diameter, height: diameter))
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    override public var frame: CGRect {
 | 
						|
        didSet {
 | 
						|
            updateRadius()
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    override public var bounds: CGRect {
 | 
						|
        didSet {
 | 
						|
            updateRadius()
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    private func updateRadius() {
 | 
						|
        self.layer.cornerRadius = self.bounds.size.height / 2
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
@objc (OWSPillView)
 | 
						|
public class PillView: UIView {
 | 
						|
 | 
						|
    public override init(frame: CGRect) {
 | 
						|
        super.init(frame: frame)
 | 
						|
 | 
						|
        // Constrain to be a pill that is at least a circle, and maybe wider.
 | 
						|
        autoPin(toAspectRatio: 1.0, relation: .greaterThanOrEqual)
 | 
						|
 | 
						|
        // low priority contstraint to ensure the pill
 | 
						|
        // is no taller than necessary
 | 
						|
        NSLayoutConstraint.autoSetPriority(.defaultLow) {
 | 
						|
            self.autoSetDimension(.height, toSize: 0)
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    required init?(coder aDecoder: NSCoder) {
 | 
						|
        fatalError("init(coder:) has not been implemented")
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    override public var frame: CGRect {
 | 
						|
        didSet {
 | 
						|
            updateRadius()
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    @objc
 | 
						|
    override public var bounds: CGRect {
 | 
						|
        didSet {
 | 
						|
            updateRadius()
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    private func updateRadius() {
 | 
						|
        layer.cornerRadius = bounds.size.height / 2
 | 
						|
    }
 | 
						|
}
 |